i updated xamarin forms to the latest version yesterday (4.3.0.947036) ,and now for some reason text alignment for Entry control is not working on android, but works fine for IOS.
anybody got a solution for this?
HorizontalTextAlignment not working
How do l ressolve System.Net.WebException Error .The Internet connection appears to be offline
The project l am building has some images on a file storage site and its consuming api's and it connected to the internet via my phone.After a lot of research l found out it has a bit to do with my using cellular network. l tried following this guide https://docs.microsoft.com/en-us/xamarin/cross-platform/macios/http-stack but it did not resolve my issue. Kindly Assist
AVAudioSession.Notifications.ObserveInterruption does not work with Google Maps
When using speech navigation in Google Maps my audio app does not get an interruption. Incoming calls and other audio apps interrupt fine. Does anybody knows why?
AVAudioSession.SharedInstance().Init();
AVAudioSession.SharedInstance().SetCategory(AVAudioSessionCategory.Playback);
AVAudioSession.Notifications.ObserveInterruption(ToneInterruptionListener);
AVAudioSession.SharedInstance().SetActive(true);
iOS Binding Unity as a library
Hi all,
I don't even know where to start
Since alpha 2019.3 Unity offers the feature "Unity as a Library" https://blogs.unity3d.com/2019/06/17/add-features-powered-by-unity-to-native-mobile-apps/ which I'm currently trying to integrate into one of our Xamarin Apps.
There are descriptions how to do that natively for Android and iOS which I got both working fine.
Just for reference:
https://forum.unity.com/threads/integration-unity-as-a-library-in-native-ios-app.685219/
https://forum.unity.com/threads/integration-unity-as-a-library-in-native-android-app.685240/
This is actually a really big deal so it is great working on it
However, I got it working fine for Xamarin Android. Now I'm trying on iOS which appears to be much more complicated.
The unity project will be exported as a native Objective-C++ framework (I think at least as there are .mm files using Objective C)
When using Sharpie to bind the framework I get a super large APIDefinitions file.
After some research I figured out that I have to define a scope to the Headers of the Framework, then the APIDefinitions are in fact much smaller and only reference the header files.
Now to my (current) problem:
If I open the ApiDefinitions then there is an interface UnityFramewok which comes from the UnityFramework.h file.
But this header holds a reference to a class UnityView which is not part of the headers. It is within the framework( at least it is within the Library project in Xcode so I assume it is bundled into the framework.)
I copied the .framework into the bindings Native References but I can't see any actual change happening when I do that.
The UnityView can not be found within the interface and I also can't import it from the library because the native reference is not available.
So how can I reference to a class of the framework from within an interface that is defined in the ApiDefinitions?
Thank you already!
Is it possible to use 2 resx file at the same time?
I need to have, in a Page, two labels
LableA
LableB (translaction of A)
For example
Autore
Author
is it possible with resx files to manage this situation?
Should I have in the resx files two strings (for example, in AppResource_it I should have "strAutore" = "Autore" and "strAutoreTranslation" = "Author") or can I have in
AppResource_it "strAutore" = "Autore"
AppResource_en "strAutore" = "Author"
and manage these in my Page?
Other solutions?
Thanks
Xamarin Forms and Dropbox integration
Is there any simple sample? I only want download a file from Dropbox (with login integrated in app) and save it in application folder.
I've spend all the day but I don't find a simple sample that:
1. Login to Dropbox.
2. Download a specified file.
I don't need browse files but yes login with different accounts. In my app, the end user sets his Dropbox account to download a file.
Thanks in advance
Xamarin.Forms consum SOAP web service on android procect
Hi,
i want to consum a soap web service with xamarin forms on adroid. I use VS2019, .netstandard 2.0 and Xamarin 16.3.0.278. I generated a web reference and in created reference.cs the important code is:
[System.Web.Services.Protocols.SoapHeaderAttribute("Activation")]
[System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestElementName="report.bundle.operation", RequestNamespace="example.com/webService", ResponseElementName="report.bundle.operationResponse", ResponseNamespace="example.com/webService", Use=System.Web.Services.Description.SoapBindingUse.Literal)]
[return: System.Xml.Serialization.XmlElementAttribute("report.bundle.operationResponse")]
public reportbundleoperationResponseType reportbundleoperation([System.Xml.Serialization.XmlElementAttribute("report.bundle.operationRequest")] reportbundleoperationRequestType reportbundleoperationRequest) {
object[] results = this.Invoke("reportbundleoperation", new object[] {
reportbundleoperationRequest});
return ((reportbundleoperationResponseType)(results[0]));
}
The used wsdl file show me the follow code part for my funktion:
wsdl:operation name="report.bundle.operation"
wsdl:input message="bo:report.bundle.operationRequest"
wsdl:output message="bo:report.bundle.operationResponse"
wsdl:fault message="bo:Result" name="FaultName"
wsdl:operation
Then i call the method reportbundleoperation from my code. When i call the method from a windows forms project with .net 4.7 the web service works fine, but wenn i try to call the method from my xamarin forms project the service is connectet but i get an error "UnknownMethod: Method 'reportbundleoperation' is unknown in Object 'WebService' every time.
Then i watched the outgoing traffic with fiddler and it showed me follow:
soap:Body soap:encodingStyle="schemas.xmlsoap.org/soap/encoding
q1:reportbundleoperation xmlns:q1="example.com/webService"
reportbundleoperationRequest href="#id1"
q1:reportbundleoperation
The outgoing call try to call the method with name reportbundleoperation in place of report.bundle.operation
I think, the problem is the part [System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestElementName="report.bundle.operation" .... .
I call the method with the name reportbundleoperation and in the web service the method named report.bundle.operation. I think the RequestElementName should transfer the name reportbundleoperation to report.bundle.operation .. isn't it?
Can sombody help me, can sombody tell me, if there is a bug in the .netstandard or in mono?
with best reguards
MH
Export scrollview as an image
Hello everybody,
I would like to export the content of a scrollview as an image, like I already did for another W8.1 project.
I know there is not a native Xamarin Forms function or method to get this result, so I started creating a **DependencyService **with no luck. Using the following code the exported image is a full screenshot of my application, and not only the content of the scrollview.
using AuditManager.Interfaces;
using AuditManager.UWP.Helpers;
using System;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Graphics.Imaging;
using Windows.Storage;
using Windows.Storage.Streams;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Xamarin.Forms;
using Xamarin.Forms.Platform.UWP;
[assembly: Dependency(typeof(ScreenshotManager))]
namespace AuditManager.UWP.Helpers
{
public class ScreenshotManager : IScreenshotManager
{
public async Task<string> CaptureAsync(View view, Rectangle size, string controlName, string pathFolder, string nomeFile)
{
RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
IVisualElementRenderer renderer = Platform.GetRenderer(view);
FrameworkElement frameworkElement = renderer.ContainerElement;
try
{
await renderTargetBitmap.RenderAsync(frameworkElement.FindControl<ScrollViewer>(controlName));
IBuffer pixelBuffer = await renderTargetBitmap.GetPixelsAsync();
StorageFolder storageFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(pathFolder, CreationCollisionOption.OpenIfExists);
StorageFile file = await storageFolder.CreateFileAsync(nomeFile, CreationCollisionOption.GenerateUniqueName);
using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, stream);
encoder.SetPixelData(
BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Straight,
(uint)renderTargetBitmap.PixelWidth,
(uint)renderTargetBitmap.PixelHeight, 96d, 96d,
pixelBuffer.ToArray());
await encoder.FlushAsync();
}
return file.Path;
}
catch (Exception ex)
{
return string.Empty;
}
}
}
}
This is the FindControl method, which always returns null:
public static T FindControl<T>(this UIElement parent, string ControlName) where T : FrameworkElement
{
if (parent == null)
return null;
if (parent.GetType() == typeof(T) && ((T)parent).Name == ControlName)
return (T)parent;
T result = null;
int count = VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < count; i++)
{
UIElement child = (UIElement)VisualTreeHelper.GetChild(parent, i);
if (FindControl<T>(child, ControlName) != null)
{
result = FindControl<T>(child, ControlName);
break;
}
}
return result;
}
So I decided to create a CustomRenderer of the scrollview, but the result is always the same. Defining an EventHandler and an event method associated to it, I correctly get the "ContainerElement" but when I try to render it with "RenderAsync" I always get null or an exception like "_Value does not fall within the expected range".
This is the CustomRenderer:
using System;
using Xamarin.Forms;
namespace AuditManager.Controls
{
public class CustomScrollView : ScrollView
{
public event EventHandler ExportAsImageRequested;
public CustomScrollView()
{
}
public string ExportAsImage(string attachFolder, string fileName, string objectName)
{
MyEventArgs eventArgs = new MyEventArgs
{
FolderName = attachFolder,
FileName = fileName,
ObjectName = objectName
};
ExportAsImageRequested?.Invoke(this, eventArgs);
return eventArgs.FilePath;
}
}
public class MyEventArgs : EventArgs
{
public string FileName { get; set; }
public string FolderName { get; set; }
public string ObjectName { get; set; }
public string FilePath { get; set; }
}
}
using System;
using System.Runtime.InteropServices.WindowsRuntime;
using AuditManager.Controls;
using AuditManager.UWP.Helpers;
using AuditManager.UWP.Renderer;
using Windows.Graphics.Imaging;
using Windows.Storage;
using Windows.Storage.Streams;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Imaging;
using Xamarin.Forms.Platform.UWP;
[assembly: ExportRenderer(typeof(CustomScrollView), typeof(CustomScrollViewRenderer))]
namespace AuditManager.UWP.Renderer
{
public class CustomScrollViewRenderer : ViewRenderer<CustomScrollView, ScrollViewer>
{
ScrollViewer scrollView;
protected override void OnElementChanged(ElementChangedEventArgs<CustomScrollView> e)
{
base.OnElementChanged(e);
if (e.OldElement != null)
{
e.OldElement.ExportAsImageRequested -= OnElementExportAsImageRequested;
}
if (e.NewElement != null)
{
if (Control == null)
{
scrollView = new ScrollViewer
{
VerticalScrollBarVisibility = ScrollBarVisibility.Hidden,
VerticalScrollMode = ScrollMode.Auto,
HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden,
HorizontalScrollMode = ScrollMode.Disabled,
VerticalAlignment = VerticalAlignment.Stretch,
HorizontalAlignment = HorizontalAlignment.Stretch,
ZoomMode = ZoomMode.Disabled,
IsEnabled = true
};
SetNativeControl(scrollView);
}
e.NewElement.ExportAsImageRequested += OnElementExportAsImageRequested;
}
}
private async void OnElementExportAsImageRequested(object sender, EventArgs e)
{
//CustomScrollView scrollView = sender as CustomScrollView;
if (e is MyEventArgs)
{
MyEventArgs evt = e as MyEventArgs;
RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
//IVisualElementRenderer renderer = scrollView.GetOrCreateRenderer();
//IVisualElementRenderer renderer = Platform.GetRenderer(scrollView);
//FrameworkElement frameworkElement = renderer.ContainerElement;
try
{
//await renderTargetBitmap.RenderAsync(frameworkElement.FindName(evt.ObjectName) as ScrollViewer);
//await renderTargetBitmap.RenderAsync(frameworkElement.FindControl<ScrollViewer>(evt.ObjectName));
await renderTargetBitmap.RenderAsync(this);
IBuffer pixelBuffer = await renderTargetBitmap.GetPixelsAsync();
StorageFolder storageFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(evt.FolderName, CreationCollisionOption.OpenIfExists);
StorageFile file = await storageFolder.CreateFileAsync(evt.FileName, CreationCollisionOption.GenerateUniqueName);
using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, stream);
encoder.SetPixelData(
BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Straight,
(uint)renderTargetBitmap.PixelWidth,
(uint)renderTargetBitmap.PixelHeight, 96d, 96d,
pixelBuffer.ToArray());
await encoder.FlushAsync();
}
evt.FilePath = file.Path;
}
catch (Exception ex)
{
evt.FilePath = string.Empty;
}
}
}
}
}
I have then another problem with the scrollviewer, but that's another story...
How can I achieve my goal?
Thanks in advance,
Matteo
GroupHeaderTemplate and ItemTemplate DataTemplateSelector conflict?
I have noticed that when I try to employ a DataTemplateSelector on both the ItemTemplate and the GroupHeaderTemplate (a different data template selector for each) in a ListView, that--at least in Android--this tends to cause an ArgumentOutOfRangeException. I'm not exactly sure why this happens but it is certainly unfortunate for what I'm trying to do. I have used DataTemplateSelectors before plenty of times for ItemTemplates and GroupHeaderTemplates, and they have worked fine, but this is the first time I have used them at the same time. While stepping through the code I have noticed two things:
- The OnSelectTemplate method for both of the DataTemplateSelectors are always called on every item, regardless of if it is a group header item or just a list item. This causes a faulty template to be returned by the group header DataTemplateSelector when a list item is being rendered (while the list item one returns the correct template) and vice versa.
- The Listview raises the exception on scroll. So when more items from the observable collection are being drawn onto the screen it somehow runs into an ArgumentOutOfRangeException.
If anyone has encountered this and has a solution or some work around it would be greatly appreciated. For the time being I'm going to try and put everything into one DataTemplateSelector that gets called for both the items and the group headers. Hopefully that will at least mitigate the faulty templates being returned.
EDIT Consolidating this into one datatemplateselector didn't work, but I guess it was worth the try.
Send data from App to service and other way around
Hi Guys,
I have implemented foreground service for my app. This service handles bluetooth communication. I need to send some data from the app to the service and the other way arround.
Messaging center doesnt seem to work.
Any ideas how to do this?
Should I use "ConfigureAwait(bool)" or not?
I followed the Visual Studio suggestion to install "Microsoft.CodeAnalysis.FxCopAnalyzers" and suddenly I get tons of new warnings.
One of them is:
Consider calling ConfigureAwait on the awaited task
So basically my await calls should change from:
await NavigationService.NavigateAsync("Navigation/Login")
to
await NavigationService.NavigateAsync("Navigation/Login").ConfigureAwait(false)
I tried to read the documentation but I am not sure about the benefit of it.
Would you recommend to make that change to all my await
calls?
Thanks!
Is there a way to hide Tab inside Shell TabBar?
I have an application where I want to display a Tab
called Upgrade when users have not paid for a subscription and never show the Tab
when they are paid users.
I have tried to find an IsVisible
property but can't... the closest thing to what I want is IsEnabled
but it leaves a blank space in the location of the now insvisible Tab
.
Does anyone know how I can achieve this? Or perhaps a better way to reach my object... thanks in advance!
Does Xamarin.Forms have a replacement for UWP's RoutedEventArgs?
I am working on converting my apps from UWP to Xamarin.Forms. A large number of my event handlers' second parameter was of type RoutedEventArgs (or a descendant of it). I often used the Handled property of this to control which controls' events were triggered. I am still very new to Xamarin.Forms, but it seems like it uses EventArgs instead (in the GestureRecognizers), which does not include this property. Is there anything I can do to gain functionality similar to that provided by RoutedEventArgs in Xamarin.Forms? Thanks.
Tabbed page ui
How to play audio from byte[]
I would like to play audio from the byte[], that is being streamed.
Unable To Change TabbedPage Tab Bar color programmatically
I am using xamarin forms To create an app. in which i need to change TabbedPage tab bar color programmatically not by Xaml when tab page change but i can't help my self. var t = FindViewById(Resource.Id.sliding_tabs); method FindViewById return null
Can I prevent a TapGestureRecognizer from swallowing touches?
I have a custom ViewCell with an Entry in it. I'm using a TapGestureRecognizer in the cell so that I can give focus to the Entry regardless of where the user taps in the cell. In my custom ViewCells without TapGestureRecognizers, I'm able to manage the pressed effect on the cells (adjusting their background color) by using a custom renderer. Unfortunately, the tap effects aren't handled by the custom renderer if the TapGestureRecognizer processes the touch. This leaves me without any sort of pressed effect highlighting for tapping the cell. Is there some way I can prevent the Xamarin TapGestureRecognizer from swallowing touches?
Xamarin Forms Webview doesn't show the tradingview widget.
Hi all,
I use a widget from tradingview site. I would like to make this implementation using xamarin forms webview. However i can't make it works. It just doesn't appear the widget at all.
The same piece of code woks correctly on a browser.
In the html code there is a script tag which the source file is from external resources(from their site).
So i would like to ask if the webview can load javascript resources from the web.
Any help will be appreciated.
Thanks in advance!
I would copy&paste the code but the forum doesn't allow me because every time i paste the code a captcha appear to check if i am human . When i click the check button the whole text disappeared. I try to post code like an answer of this question.
ListView Alternative or Solution Suggestion?
I'm going to attempt to keep this short.
I'm Busy working on a Mobile Application With Xamarin as the Front end and Woo-commerce as the Back End, Using the Woocommerce.net Wrapper(Can be found on Github at XiaoFaye) To connect with the Api and Pull products/Suppliers ect.
Now the issue's Ive Faced is that, When Creating the list of products with a ListView, I can set everything threw a Products Collection easily except for the Image's and Attributes(It's pretty much the same problem) The images are part of a Nested Class inside of "Products" Called "Images" I need the Source from that Nested Class to set my Listviews(Image) Source, Now I have trouble accessing that nested class(This is a lack of Knowledge on my side for sure), Even if I did it's returned as a list and i'm not sure if you can even bind to a List or a Item in a List (Not setting the Overall Source but just 1 Listview Item's Source). I'll be honest I dont have nearly the experience to be making something like this. So I'm Wondering if Someone has a Suggestion for things I can lookup to maybe resolve this issue, I'd love to solve this just a little out of idea's.
public class ProductBatch : BatchObject { }
[DataContract]
public class Product : JsonObject
{
public static string Endpoint { get { return "products"; } }
/// <summary>
/// Unique identifier for the resource.
/// read-only
/// </summary>
[DataMember(EmitDefaultValue = false)]
public int? id { get; set; }
/// <summary>
/// Product name.
/// </summary>
[DataMember(EmitDefaultValue = false)]
public string name { get; set; }
[DataMember(EmitDefaultValue = false)]
public List<ProductImage> images { get; set; }
public class ProductImage //Nested Classs
{
///
/// Image ID.
///
[DataMember(EmitDefaultValue = false)]
public long? id { get; set; }
/// <summary>
/// The date the image was created, in the site’s timezone.
/// read-only
/// </summary>
[DataMember(EmitDefaultValue = false)]
public DateTime? date_created { get; set; }
/// <summary>
/// The date the image was created, as GMT.
/// read-only
/// </summary>
[DataMember(EmitDefaultValue = false)]
public DateTime? date_created_gmt { get; set; }
/// <summary>
/// The date the image was last modified, in the site’s timezone.
/// read-only
/// </summary>
[DataMember(EmitDefaultValue = false)]
public DateTime? date_modified { get; set; }
/// <summary>
/// The date the image was last modified, as GMT.
/// read-only
/// </summary>
[DataMember(EmitDefaultValue = false)]
public DateTime? date_modified_gmt { get; set; }
/// <summary>
/// Image URL.
/// </summary>
[DataMember(EmitDefaultValue = false)]
public string src { get; set; }
/// <summary>
/// Image name.
/// </summary>
[DataMember(EmitDefaultValue = false)]
public string name { get; set; }
/// <summary>
/// Image alternative text.
/// </summary>
[DataMember(EmitDefaultValue = false)]
public string alt { get; set; }
/// <summary>
/// Image position. 0 means that the image is featured.
/// </summary>
[DataMember(EmitDefaultValue = false)]
public int? position { get; set; }
}
Just a little example of the Class Structure.
<ListView.ItemTemplate>
<ViewCell.View>
<Image Source="{Binding ??? }"/>
<Label Text="{Binding date_created, StringFormat='{0:dd/MM/yyyy}'}" FontSize="Small" FontAttributes="Italic"/>
<Label Text="{Binding price }"/>
<Label Text="{x:Binding enable_html_description }" FontSize="Medium"/>
<Label Text="{x:Binding sku}" FontSize="Medium"/>
<Button BindingContext="{Binding id}" Clicked="ProductClicked"></Button>
</StackLayout>
</Frame>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Unit testing Prism ClearPopupStackAsync
We are developing a Xamarin Forms (4.1.0.778454) application using Prism (7.1.0.431). While writing unit test cases using NUnit and Moq, the following error occurred when the code reaches the statement "_navigationService.ClearPopupStackAsync
".
System.InvalidOperationException: 'You MUST install Rg.Plugins.Popup to each project and call Rg.Plugins.Popup.Popup.Init(); prior to using it.
The instance of INavigationService is supplied by constructor injection. So that, in unit tests we are using Mock objects of INavigationService.
While analyzing, I found that ClearPopupStackAsync is an extension method, so that it cannot be mocked. Can anyone suggest some alternative for mocking?