Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all 91519 articles
Browse latest View live

Unable to write on SD card

$
0
0

Hi,

I can't write or simply move a file stored on SD card. I have no exceptions

  • reading/writing files on the phone storage
  • reading files on the SD card

Certainly the permssions are present in the AndroidManifest.xml file

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

and they are given during runtime.

So everytime I try to write on SD card a "System.UnauthorizedAccessException: Access to the path is denied." is thrown.
You can reproduce it with this simple code

            void MoveFile(string path)
            {
                string newpath = path + ".mp3";

                System.IO.File.Move(path, newpath);

                Console.WriteLine("----------------- File moved! ------------------".ToUpper());
            }

Right after the System.IO.File.Move(path, newpath); statement is thrown a System.UnauthorizedAccessException.


Stop capturing events on a component so underlying control receives event

$
0
0

I have two controls, one on top of the other for visual purposes e.g. a label with an entry, style wise our designer wants the label to sit partially on top of the entry, this ends up capturing touch events on the Entry control, is there a way to make a control dumb and non-capturing for events? Something similar to pointer-events: none in a web environment?

System.ArgumentException: 'Delegate to an instance method cannot have null 'this'.' - UWP

$
0
0

Hello,

I'm struggling with an exception that I'm getting when trying to run my Xamarin.Forms UWP app. This is a legacy application that I'm working on that is currently on Xamarin.Forms 3.1.0.697729. I have to upgrade it to Xamarin.Forms 3.6.0.709228. to resolve an issue that is present in iPadOS 13 (because this is a legacy app, we don't want to upgrade Xamarin.Forms to the latest because we are in the process of deprecating this app within the next year, so we don't want to put a ton of effort into upgrading this to XF 4.5, when we're already doing that with our newer app).

Unfortunately, upgrading from XF 3.1 to 3.6 is causing an exception to occur in our UWP app when we're trying to set the MainPage of the application. The only thing that has changed is this XF NuGet package upgrade. Everything else is exactly the same. The app works perfectly fine with XF 3.1, but with XF 3.6, we get a System.ArgumentException with the message of: 'Delegate to an instance method cannot have null 'this'.' I tried doing some searches for how to resolve this issue, but I haven't come across anything useful for this specific case. Since this error started happening after an upgrade of Xamarin.Forms, I figured I would make a post here to see if anyone here has experienced an issue like this before and/or has ideas on a potential fix. Please let me know if there is anything else I can provide to help track this issue down. I appreciate any assistance I can get with this one.

Unfortunately, the stack trace & call stacks I get when the error occurs aren't super helpful, but here they are, just in case there is something useful that can be spotted inside of them:

`Stack Trace:
System.ArgumentException
HResult=0x80070057
Message=Delegate to an instance method cannot have null 'this'.
Source=System.Private.CoreLib
StackTrace:
at System.MulticastDelegate.ThrowNullThisInDelegateToInstance()

Call Stack:
System.Private.CoreLib.dll!System.MulticastDelegate.ThrowNullThisInDelegateToInstance() Unknown
Xamarin.Forms.Platform.UAP.dll!Xamarin.Forms.Platform.UWP.TitleViewManager.TitleViewManager(Xamarin.Forms.Platform.UWP.ITitleViewRendererController titleViewRendererController) Unknown
Xamarin.Forms.Platform.UAP.dll!Xamarin.Forms.Platform.UWP.MasterDetailControl.OnApplyTemplate() Unknown
[Native to Managed Transition]
[Managed to Native Transition]
Xamarin.Forms.Platform.UAP.dll!Xamarin.Forms.Platform.UWP.MasterDetailControl.Xamarin.Forms.Platform.UWP.IToolbarProvider.GetCommandBarAsync() Unknown
Xamarin.Forms.Platform.UAP.dll!Xamarin.Forms.Platform.UWP.MasterDetailPageRenderer.Xamarin.Forms.Platform.UWP.IToolbarProvider.GetCommandBarAsync() Unknown
Xamarin.Forms.Platform.UAP.dll!Xamarin.Forms.Platform.UWP.Platform.UpdateToolbarItems() Unknown
Xamarin.Forms.Platform.UAP.dll!Xamarin.Forms.Platform.UWP.Platform.OnToolbarItemsChanged(object sender, System.EventArgs e) Unknown
Xamarin.Forms.Core.dll!Xamarin.Forms.Internals.ToolbarTracker.EmitCollectionChanged() Unknown
Xamarin.Forms.Core.dll!Xamarin.Forms.Internals.ToolbarTracker.Target.set(Xamarin.Forms.Page value) Unknown
Xamarin.Forms.Platform.UAP.dll!Xamarin.Forms.Platform.UWP.Platform.UpdateToolbarTracker() Unknown
Xamarin.Forms.Platform.UAP.dll!Xamarin.Forms.Platform.UWP.Platform.SetCurrent(Xamarin.Forms.Page newPage, bool popping, System.Action completedCallback) Unknown
Xamarin.Forms.Platform.UAP.dll!Xamarin.Forms.Platform.UWP.Platform.SetPage(Xamarin.Forms.Page newRoot) Unknown
Xamarin.Forms.Platform.UAP.dll!Xamarin.Forms.Platform.UWP.WindowsBasePage.OnApplicationPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) Unknown
Xamarin.Forms.Core.dll!Xamarin.Forms.BindableObject.OnPropertyChanged(string propertyName) Unknown
Xamarin.Forms.Core.dll!Xamarin.Forms.Element.OnPropertyChanged(string propertyName) Unknown
Xamarin.Forms.Core.dll!Xamarin.Forms.Application.MainPage.set(Xamarin.Forms.Page value) Unknown

Mobile2.Forms.dll!Mobile2.Forms.FormsApp.LoginUser(string username, string password, string company) Line 756 C#

[Resuming Async Method]
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner..cctor.AnonymousMethod__4_0(object sm) Unknown
System.Private.CoreLib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.RunWithDefaultContext() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.OutputAsyncCausalityEvents.AnonymousMethod__0() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__0() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke() Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.InvokeAction(object state) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunCallback(System.Threading.ContextCallback callback, object state, ref System.Threading.Tasks.Task currentTask) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.Run(System.Threading.Tasks.Task task, bool canInlineContinuationTask) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task<System.__Canon>.TrySetResult(System.__Canon result) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<Xamarin.Forms.Page>.SetExistingTaskResult(Xamarin.Forms.Page result) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<Xamarin.Forms.Page>.SetResult(Xamarin.Forms.Page result) Unknown
[Completed] Mobile2.Forms.dll!Mobile2.Forms.FormsApp.GetMainPage() Line 600 C#
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner..cctor.AnonymousMethod__4_0(object sm) Unknown
System.Private.CoreLib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.RunWithDefaultContext() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.OutputAsyncCausalityEvents.AnonymousMethod__0() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__0() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke() Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.InvokeAction(object state) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunCallback(System.Threading.ContextCallback callback, object state, ref System.Threading.Tasks.Task currentTask) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.Run(System.Threading.Tasks.Task task, bool canInlineContinuationTask) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task<System.Threading.Tasks.VoidTaskResult>.TrySetResult(System.Threading.Tasks.VoidTaskResult result) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.SetExistingTaskResult(System.Threading.Tasks.VoidTaskResult result) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.SetResult(System.Threading.Tasks.Task<System.Threading.Tasks.VoidTaskResult> completedTask) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult() Unknown
[Completed] Mobile2.Forms.dll!Mobile2.Forms.ViewModels.BaseAsyncViewModel.Initialize() Line 73 C#
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner..cctor.AnonymousMethod__4_0(object sm) Unknown
System.Private.CoreLib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.RunWithDefaultContext() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.OutputAsyncCausalityEvents.AnonymousMethod__0() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__0() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke() Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.InvokeAction(object state) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunCallback(System.Threading.ContextCallback callback, object state, ref System.Threading.Tasks.Task currentTask) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.Run(System.Threading.Tasks.Task task, bool canInlineContinuationTask) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task<System.Threading.Tasks.VoidTaskResult>.TrySetResult(System.Threading.Tasks.VoidTaskResult result) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.SetExistingTaskResult(System.Threading.Tasks.VoidTaskResult result) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.SetResult(System.Threading.Tasks.Task<System.Threading.Tasks.VoidTaskResult> completedTask) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult() Unknown
[Completed] Mobile2.Forms.dll!Mobile2.Forms.ViewModels.BaseAsyncViewModel.Reload(bool isPullToRefresh) Line 66 C#
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner..cctor.AnonymousMethod__4_0(object sm) Unknown
System.Private.CoreLib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.RunWithDefaultContext() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.OutputAsyncCausalityEvents.AnonymousMethod__0() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__0() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke() Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.InvokeAction(object state) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunCallback(System.Threading.ContextCallback callback, object state, ref System.Threading.Tasks.Task currentTask) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.Run(System.Threading.Tasks.Task task, bool canInlineContinuationTask) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task<System.Threading.Tasks.VoidTaskResult>.TrySetResult(System.Threading.Tasks.VoidTaskResult result) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.SetExistingTaskResult(System.Threading.Tasks.VoidTaskResult result) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.SetResult(System.Threading.Tasks.Task<System.Threading.Tasks.VoidTaskResult> completedTask) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult() Unknown
[Completed] Mobile2.Forms.dll!Mobile2.Forms.ViewModels.MenuListViewModel.LoadData() Line 198 C#
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner..cctor.AnonymousMethod__4_0(object sm) Unknown
System.Private.CoreLib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.RunWithDefaultContext() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.OutputAsyncCausalityEvents.AnonymousMethod__0() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__0() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke() Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.GetActionLogDelegate.AnonymousMethod__0() Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation..cctor.AnonymousMethod__8_0(object state) Unknown
System.Runtime.WindowsRuntime.dll!System.Threading.WinRTSynchronizationContextBase.Invoker.InvokeCore() Unknown
System.Runtime.WindowsRuntime.dll!System.Threading.WinRTSynchronizationContextBase.Invoker.InvokeInContext(object thisObj) Unknown
System.Private.CoreLib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
System.Runtime.WindowsRuntime.dll!System.Threading.WinRTSynchronizationContextBase.Invoker.Invoke() Unknown`

ContentView lifecycle

$
0
0

Hi,

First I'm a huge fan of Xamarin & Xamarin.Forms, it is simply amazing !

My question is :

I am creating a XAML ContentView which has animations looping while the IsVisible property is true and it works fine.

However, how can I detect from this custom control that its containing page has been removed or is not visible anymore when navigating back or forward to another page ? It seems that when navigating back to my first page my component (on the 2nd page) is not destroyed.

Thank you very much,

Have a nice day :-) !

(Android) Force every page on portrait except one which could be portrait or landscape

$
0
0

Hello,

I am trying to achieve the following :

On tablet, the orientation should be allowed to both portrait or landscape whenever the user wants

On Phone, the orientation should be forced to portrait except on the gallery which is one single view, where both orientation are allowed.

On iOS, this works fine, but on Android, that's harder to get.

The first thing I tried is to use the OnConfigurationChange event, adding the flags :

       ConfigurationChanges =  ConfigChanges.Orientation | ConfigChanges.ScreenSize

In the MainActivity.

However, by doing that, when I set the requestedOrientation, the event isn't triggered anymore.

Then I focused on some post I saw which indicate that the MessagingCenter is needed. So that's what I tried :

On the MainActivity :

        if (Device.Idiom == TargetIdiom.Phone)
        {
            RequestedOrientation = ScreenOrientation.Portrait;

            MessagingCenter.Subscribe<Gallery>(this, "AllowLandscape", sender =>
            {
                RequestedOrientation = ScreenOrientation.Landscape;
            });

            MessagingCenter.Subscribe<Gallery>(this, "PreventLandscape", sender =>
            {
                RequestedOrientation = ScreenOrientation.Portrait;
            });
        }

And then I allowed LandScape by sending the message in the Gallery OnAppearing, but it forces the orientation to Landscape where I want it to be free.

Then I sent the PreventLanscape message OnDisappearing

Okay that almost did the trick, and I could eventually say to the customer that the easier is to force Landscape on the gallery.

The things are that using that also "repainted" views from NavigationStack and that some pictures are now on Landscape Format and not Portrait even if OnDisappearing I sent the message to set it back to Portrait.

So here is my question : Whats the good way to deal with this problem ? Is it even possible ?

Some infos : Using Xam Forms 4.5.0.396 / Essentials 1.5.1

Custom TimeControler doesnt work while add from code Behind on ios

$
0
0

Hi, I am struggling with a stupid problem, I have made a custom TimePicker for Ios, it works perfectly when it is added in xaml

 <customControls:CustomTimePicker
                        x:Name="EndHour"
                        Grid.Row="9"
                        Grid.Column="1"
                        Focused="MyEndTimePicker_Focused"
                        Format="HH:mm"
                        HorizontalOptions="FillAndExpand"
                        PropertyChanged="ChangedEndHour"
                        PropertyChanging="OldChangedEndHour"
                        Style="{StaticResource MainTimeStyle}"
                        Time="{Binding EndHour}" />

but when I add this control form code behind

var leftTimePicker = new CustomTimePicker { HorizontalOptions = LayoutOptions.Center };
                var rightTimePicker = new CustomTimePicker { HorizontalOptions = LayoutOptions.Center };
                var rowToChange = MainGrid.RowDefinitions.ElementAt(RowNumber);

                var finalHeight = rowToChange.Height.Value + RowHeight;

                rowToChange = new RowDefinition { Height = new GridLength(finalHeight, GridUnitType.Star) };

                MainGrid.RowDefinitions[RowNumber] = rowToChange;

                var label = new Label { TextColor = Color.Blue };

                switch (dayPrior.Key)
                {
                    case "Mon":
                        label.Text = "Poniedziałek";
                        leftTimePicker.SetBinding(CustomTimePicker.TimeProperty, "MonStartHour");
                        rightTimePicker.SetBinding(CustomTimePicker.TimeProperty, "MonEndHour");
                        break;

This is my custom picker

 public class CustomTimePickerRenderer : TimePickerRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<TimePicker> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                var timePicker = (UIDatePicker)Control.InputView;
                timePicker.Locale = new NSLocale("no_nb");

                if (Element != null && !Element.Time.Equals(default(TimeSpan)))
                    Control.Text = Element.Time.ToString(@"hh\:mm");
                else
                    Control.Text = DateTime.Now.ToString("HH:mm");
            }
        }      
    }

System.ArgumentException: 'Delegate to an instance method cannot have null 'this'.' - UWP

$
0
0

Hello,

I'm struggling with an exception that I'm getting when trying to run my Xamarin.Forms UWP app. This is a legacy application that I'm working on that is currently on Xamarin.Forms 3.1.0.697729. I have to upgrade it to Xamarin.Forms 3.6.0.709228. to resolve an issue that is present in iPadOS 13 (because this is a legacy app, we don't want to upgrade Xamarin.Forms to the latest because we are in the process of deprecating this app within the next year, so we don't want to put a ton of effort into upgrading this to XF 4.5, when we're already doing that with our newer app).

Unfortunately, upgrading from XF 3.1 to 3.6 is causing an exception to occur in our UWP app when we're trying to set the MainPage of the application. The only thing that has changed is this XF NuGet package upgrade. Everything else is exactly the same. The app works perfectly fine with XF 3.1, but with XF 3.6, we get a System.ArgumentException with the message of: 'Delegate to an instance method cannot have null 'this'.' I tried doing some searches for how to resolve this issue, but I haven't come across anything useful for this specific case. Since this error started happening after an upgrade of Xamarin.Forms, I figured I would make a post here to see if anyone here has experienced an issue like this before and/or has ideas on a potential fix. Please let me know if there is anything else I can provide to help track this issue down. I appreciate any assistance I can get with this one.

Unfortunately, the stack trace & call stacks I get when the error occurs aren't super helpful, but here they are, just in case there is something useful that can be spotted inside of them:

`Stack Trace:
System.ArgumentException
HResult=0x80070057
Message=Delegate to an instance method cannot have null 'this'.
Source=System.Private.CoreLib
StackTrace:
at System.MulticastDelegate.ThrowNullThisInDelegateToInstance()

Call Stack:
System.Private.CoreLib.dll!System.MulticastDelegate.ThrowNullThisInDelegateToInstance() Unknown
Xamarin.Forms.Platform.UAP.dll!Xamarin.Forms.Platform.UWP.TitleViewManager.TitleViewManager(Xamarin.Forms.Platform.UWP.ITitleViewRendererController titleViewRendererController) Unknown
Xamarin.Forms.Platform.UAP.dll!Xamarin.Forms.Platform.UWP.MasterDetailControl.OnApplyTemplate() Unknown
[Native to Managed Transition]
[Managed to Native Transition]
Xamarin.Forms.Platform.UAP.dll!Xamarin.Forms.Platform.UWP.MasterDetailControl.Xamarin.Forms.Platform.UWP.IToolbarProvider.GetCommandBarAsync() Unknown
Xamarin.Forms.Platform.UAP.dll!Xamarin.Forms.Platform.UWP.MasterDetailPageRenderer.Xamarin.Forms.Platform.UWP.IToolbarProvider.GetCommandBarAsync() Unknown
Xamarin.Forms.Platform.UAP.dll!Xamarin.Forms.Platform.UWP.Platform.UpdateToolbarItems() Unknown
Xamarin.Forms.Platform.UAP.dll!Xamarin.Forms.Platform.UWP.Platform.OnToolbarItemsChanged(object sender, System.EventArgs e) Unknown
Xamarin.Forms.Core.dll!Xamarin.Forms.Internals.ToolbarTracker.EmitCollectionChanged() Unknown
Xamarin.Forms.Core.dll!Xamarin.Forms.Internals.ToolbarTracker.Target.set(Xamarin.Forms.Page value) Unknown
Xamarin.Forms.Platform.UAP.dll!Xamarin.Forms.Platform.UWP.Platform.UpdateToolbarTracker() Unknown
Xamarin.Forms.Platform.UAP.dll!Xamarin.Forms.Platform.UWP.Platform.SetCurrent(Xamarin.Forms.Page newPage, bool popping, System.Action completedCallback) Unknown
Xamarin.Forms.Platform.UAP.dll!Xamarin.Forms.Platform.UWP.Platform.SetPage(Xamarin.Forms.Page newRoot) Unknown
Xamarin.Forms.Platform.UAP.dll!Xamarin.Forms.Platform.UWP.WindowsBasePage.OnApplicationPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) Unknown
Xamarin.Forms.Core.dll!Xamarin.Forms.BindableObject.OnPropertyChanged(string propertyName) Unknown
Xamarin.Forms.Core.dll!Xamarin.Forms.Element.OnPropertyChanged(string propertyName) Unknown
Xamarin.Forms.Core.dll!Xamarin.Forms.Application.MainPage.set(Xamarin.Forms.Page value) Unknown

Mobile2.Forms.dll!Mobile2.Forms.FormsApp.LoginUser(string username, string password, string company) Line 756 C#

[Resuming Async Method]
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner..cctor.AnonymousMethod__4_0(object sm) Unknown
System.Private.CoreLib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.RunWithDefaultContext() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.OutputAsyncCausalityEvents.AnonymousMethod__0() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__0() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke() Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.InvokeAction(object state) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunCallback(System.Threading.ContextCallback callback, object state, ref System.Threading.Tasks.Task currentTask) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.Run(System.Threading.Tasks.Task task, bool canInlineContinuationTask) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task<System.__Canon>.TrySetResult(System.__Canon result) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<Xamarin.Forms.Page>.SetExistingTaskResult(Xamarin.Forms.Page result) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<Xamarin.Forms.Page>.SetResult(Xamarin.Forms.Page result) Unknown
[Completed] Mobile2.Forms.dll!Mobile2.Forms.FormsApp.GetMainPage() Line 600 C#
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner..cctor.AnonymousMethod__4_0(object sm) Unknown
System.Private.CoreLib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.RunWithDefaultContext() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.OutputAsyncCausalityEvents.AnonymousMethod__0() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__0() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke() Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.InvokeAction(object state) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunCallback(System.Threading.ContextCallback callback, object state, ref System.Threading.Tasks.Task currentTask) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.Run(System.Threading.Tasks.Task task, bool canInlineContinuationTask) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task<System.Threading.Tasks.VoidTaskResult>.TrySetResult(System.Threading.Tasks.VoidTaskResult result) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.SetExistingTaskResult(System.Threading.Tasks.VoidTaskResult result) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.SetResult(System.Threading.Tasks.Task<System.Threading.Tasks.VoidTaskResult> completedTask) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult() Unknown
[Completed] Mobile2.Forms.dll!Mobile2.Forms.ViewModels.BaseAsyncViewModel.Initialize() Line 73 C#
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner..cctor.AnonymousMethod__4_0(object sm) Unknown
System.Private.CoreLib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.RunWithDefaultContext() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.OutputAsyncCausalityEvents.AnonymousMethod__0() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__0() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke() Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.InvokeAction(object state) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunCallback(System.Threading.ContextCallback callback, object state, ref System.Threading.Tasks.Task currentTask) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.Run(System.Threading.Tasks.Task task, bool canInlineContinuationTask) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task<System.Threading.Tasks.VoidTaskResult>.TrySetResult(System.Threading.Tasks.VoidTaskResult result) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.SetExistingTaskResult(System.Threading.Tasks.VoidTaskResult result) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.SetResult(System.Threading.Tasks.Task<System.Threading.Tasks.VoidTaskResult> completedTask) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult() Unknown
[Completed] Mobile2.Forms.dll!Mobile2.Forms.ViewModels.BaseAsyncViewModel.Reload(bool isPullToRefresh) Line 66 C#
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner..cctor.AnonymousMethod__4_0(object sm) Unknown
System.Private.CoreLib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.RunWithDefaultContext() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.OutputAsyncCausalityEvents.AnonymousMethod__0() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__0() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke() Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.InvokeAction(object state) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunCallback(System.Threading.ContextCallback callback, object state, ref System.Threading.Tasks.Task currentTask) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.Run(System.Threading.Tasks.Task task, bool canInlineContinuationTask) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task<System.Threading.Tasks.VoidTaskResult>.TrySetResult(System.Threading.Tasks.VoidTaskResult result) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.SetExistingTaskResult(System.Threading.Tasks.VoidTaskResult result) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.SetResult(System.Threading.Tasks.Task<System.Threading.Tasks.VoidTaskResult> completedTask) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult() Unknown
[Completed] Mobile2.Forms.dll!Mobile2.Forms.ViewModels.MenuListViewModel.LoadData() Line 198 C#
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner..cctor.AnonymousMethod__4_0(object sm) Unknown
System.Private.CoreLib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.RunWithDefaultContext() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.OutputAsyncCausalityEvents.AnonymousMethod__0() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__0() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke() Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.GetActionLogDelegate.AnonymousMethod__0() Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation..cctor.AnonymousMethod__8_0(object state) Unknown
System.Runtime.WindowsRuntime.dll!System.Threading.WinRTSynchronizationContextBase.Invoker.InvokeCore() Unknown
System.Runtime.WindowsRuntime.dll!System.Threading.WinRTSynchronizationContextBase.Invoker.InvokeInContext(object thisObj) Unknown
System.Private.CoreLib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
System.Runtime.WindowsRuntime.dll!System.Threading.WinRTSynchronizationContextBase.Invoker.Invoke() Unknown`

ContentView lifecycle

$
0
0

Hi,

First I'm a huge fan of Xamarin & Xamarin.Forms, it is simply amazing !

My question is :

I am creating a XAML ContentView which has animations looping while the IsVisible property is true and it works fine.

However, how can I detect from this custom control that its containing page has been removed or is not visible anymore when navigating back or forward to another page ? It seems that when navigating back to my first page my component (on the 2nd page) is not destroyed.

Thank you very much,

Have a nice day :-) !


Xamarin.AndroidX.Work.Runtime 2.3.3

$
0
0

Hi @DavidOrtinau
after upgrading to Xamarin.AndroidX.Work.Runtime 2.3.3 i got this error when start debugging the app
Java.Lang.NoClassDefFoundError: 'Failed resolution of: Landroidx/work/impl/WorkDatabase;'

iOS and Android different behaviors for OnAppearing

$
0
0

Hello!

I am running into an issue (one that I could probably resolve a different way, but I wanted to make sure this is an issue) where when OnAppearing gets called is different for Android and iOS.

As an example, I have a root TabbedPage, and then I PushModalAsync a LoginPage (ContentPage) on top of it, and afterwards PopModalAsync. For iOS, the OnAppearing method for the TabbedPage seems to get called when the TabbedPage gets created, as well as when the LoginPage gets popped. This makes sense to some extent according to the documentation as the TabbedPage is probably "visible" initially that I can't actually see, then LoginPage is pushed immediately, then when popped, the TabbedPage is visible again. (Just FYI, the documentation for OnAppearing says "When overridden, allows application developers to customize behavior immediately prior to the Xamarin.Forms.Page becoming visible."

For Android though, the OnAppearing method gets called at the beginning, but not again when after the PopModalAsync. Has anyone else ran into this behavior? Anyone know at least a quick solution for now (as in a way to force call OnAppearing on the TabbedPage from the LoginPage)?

Thank you!

Faster/Better to have style.xaml for each view or combine into a theme file?

$
0
0

In terms of speed, performance, appsize, etc - is it better to create a Styles.xaml for each view in my app or to combine the control styles, etc into 1 theme file?

Using with Facebook login in xamarin form

$
0
0

I Use Xamarin.Auth for login with Facebook Account, Facebook'sProfile photo Resolution is not clear in my App.

private void FacebookClicked(object sender)
{
PublicClass.LocalStorage.ClearAllStorage();
Helper.Constants.AuthSignUp = 1;
Helper.Settings.GeneralUserType = "";
DependencyService.Get().facebook();
}

**Dependency Service **

public class FacebookAuth : BaseViewModel, IFacebook
{
public void facebook()
{
var auth = new OAuth2Authenticator(
clientId: "1106049452932664",
scope: "email",
authorizeUrl: new System.Uri("https://m.facebook.com/dialog/oauth"),
redirectUrl: new System.Uri("https://www.facebook.com/connect/login_success.html"));

        auth.Completed += Auth_Completed;
        var ui = auth.GetUI((Activity)Forms.Context);
        ((Activity)Forms.Context).StartActivity(ui);
    }

    private async void Auth_Completed(object sender, AuthenticatorCompletedEventArgs e)
    {
        if (e.IsAuthenticated)
        {
            UserDialogs.Instance.ShowLoading();
            var request = new OAuth2Request(
                                            "GET",
                                            new System.Uri("https://graph.facebook.com/me?fields=email,name,first_name,last_name,gender,picture"),//https://graph.facebook.com/me?fields=name,picture,cover,birthday //https://graph.facebook.com/me?fields=email,name,first_name,last_name,gender,picture
                                            null,
                                            e.Account);

            var fbResponse = await request.GetResponseAsync();

            //var fbUserAccessToken = CrossFacebookClient.Current.ActiveToken;
            var obj = JObject.Parse(fbResponse.GetResponseText());
            var email = string.Empty;
            try
            {
                email = obj["email"].ToString().Replace("\"", "");
            }
            catch (Exception ex)
            {
                email = "psycho@gmail.com";
            }
            var FacebookAccessToken = e.Account.Properties["access_token"];
            var json = fbResponse.GetResponseText();
            var fbUser = JsonConvert.DeserializeObject<FacebookUserModel>(json);
            var name = fbUser.name;
            Helper.Constants.AuthUserEmail = email;
            Helper.Constants.AuthUserFName = fbUser.name;
            Helper.Constants.AuthUserLName = fbUser.last_name;
            Helper.Constants.AuthUserPhone = string.Empty;
            Helper.Constants.AuthUserProfilePic = fbUser.picture.data.url;
            Xamarin.Forms.MessagingCenter.Send<string>(Convert.ToString(Helper.Constants.isAuthLogin), "AuthLogin");
        }
    }
}

Navigation and passing of data between multiple pages

$
0
0

Navigation: Page 1 > Page 2 > Page 3 > Page 1

I want to update my label in Page 1 from Page 3. Meaning when user click 'Done' in Page 3, I will navigate back to Page 1 with the label updated.
I tried using Navigation.PopAsync() but it redirects me to Page 2 instead.
I also tried using
`for (var counter = 1; counter < BackCount; counter++)
{

            Navigation.RemovePage(Navigation.NavigationStack[Navigation.NavigationStack.Count - 2]);
        }
        await Navigation.PopAsync();`

but it does not update the label.
Does anyone know how to navigate back to Page 1 from Page 3 while passing data? (label update)

Xamarin.Forms Android app Lags when switching Master-Detail page

$
0
0

I'm using Xamain.Forms version 4.5.0.356.
Any suggestion on how to solve this?

Thanks in advance.

Does anyone have a good example of Amazon In-App purchase code

$
0
0

I set up my code so that it first checks if the user can purchase (or has purchased) a non consumable from Amazon. If not, then the user must have used the Google store and the app then uses James Montemagno's In-App purchase plugin (which is pretty freaking awesome BTW).

Does anyone have code that checks Amazon for a non-consumable (Entitled Content) and purchases it? Thanks in advance!


Xamarin forms: Absolute Layout Listview Scrolling is not working

$
0
0

I have a listview inside an AbsoluteLayout and my problem is listview scrolling is not working.

Please see the below screenshot of code:

enter image description here

And the output screen is like below:

enter image description here

I have added AbsoluteLayout for putting the Imagebutton on top of Listview. If I cover the AbsoluteLayout with a scrollview, then scrolling works, but the Imagebutton is not showing on top of Listview. It is placed on the bottom after listview items.

Please suggest a solution for this, Thanks.

I want to update one property of an object inside ObservableCollection

$
0
0

Hi , I am struggling with a problem, my ObservableCollection doest refresh after change in code behind.

  private ObservableCollection<NotificationModel> _notifications = new ObservableCollection<NotificationModel>();

        public ObservableCollection<NotificationModel> Notifications
        {
            get => _notifications;
            set
            {
                _notifications = value;
                RaisePropertyChanged(nameof(Notifications));
            }
        }

this is my list,

After click on some item I Want to update the color of it

 var notification =  _notifications.First(x => x.Id == itemInfo.Id);
                notification.NotificationColor = "#FFFFFF";

but it doesnt work

Read cookies from PCL

$
0
0

Hello
I would like to read cookie value, which is set by javascript in a webview
The webview is implemented and managed within PCL project
The following code is executed without errors but allows to get only an empty object CookieCollection
Can you please help?

private void webView_Navigated(object sender, WebNavigatedEventArgs e)
        {
            if (e.Result == WebNavigationResult.Success)
            {
                try
                {
                    var assembly = typeof(App).GetTypeInfo().Assembly;
                    Stream stream = assembly.GetManifestResourceStream("script.js");
                    string script = "";
                    using (var reader = new StreamReader(stream))
                    {
                        script = reader.ReadToEnd();
                    }
                    webView.Eval(script);
                    string url = ((UrlWebViewSource)webView.Source).Url;
                    var handler = new HttpClientHandler { CookieContainer = new CookieContainer() };
                    var httpClient = new HttpClient(handler);
                    CookieCollection Cookies = handler.CookieContainer.GetCookies(new Uri(url));
                    if (Cookies.Count > 0)
                    {
                        string value = Cookies["location"].Value;
                    }
                }
                catch (Exception ex)
                {
                    string message = ex.Message;
                }
            }
        }

Using DataTemplate in Custom View?

$
0
0

I am currently trying to get make a custom view where I will make a grid where each children has a view that is defined by the user, then I define a DataSource with a list of items. However, I can't figure out how to make this in a custom view; the only thing I see when looking in google is the DataTemplate usage but for ListView and CollectionView, which I am not using. Any Ideas?

Code for teh Custom View:

[DesignTimeVisible(true)]
public class OptionsSliderView : ContentView
{

        #region BindableProperty: ItemTemplate.
        public static readonly BindableProperty ItemTemplateProperty = BindableProperty.Create(nameof(ItemTemplate), typeof(DataTemplate), typeof(OptionsSliderView), propertyChanged: ItemTemplatePropertyChanged, defaultValue: null);
        public DataTemplate ItemTemplate
        {
            get { return (DataTemplate)GetValue(ItemTemplateProperty); }
            set { SetValue(ItemTemplateProperty, value); }
        }

        private static void ItemTemplatePropertyChanged(BindableObject bindable, object oldValue, object newValue)
        {
            var mBindable = (OptionsSliderView)bindable;
            var mOldValue = (DataTemplate)oldValue;
            var mNewValue = (DataTemplate)newValue;

            if (mOldValue != mNewValue) { BuildSlider(mBindable, itemTemplate: mNewValue); }
        }
        #endregion

        #region BindableProperty: ItemHeaderTemplate.
        public static readonly BindableProperty ItemHeaderTemplateProperty = BindableProperty.Create(nameof(ItemHeaderTemplate), typeof(DataTemplate), typeof(OptionsSliderView), propertyChanged: ItemHeaderTemplatePropertyChanged, defaultValue: null);
        public DataTemplate ItemHeaderTemplate
        {
            get { return (DataTemplate)GetValue(ItemHeaderTemplateProperty); }
            set { SetValue(ItemHeaderTemplateProperty, value); }
        }

        private static void ItemHeaderTemplatePropertyChanged(BindableObject bindable, object oldValue, object newValue)
        {
            var mBindable = (OptionsSliderView)bindable;
            var mOldValue = (DataTemplate)oldValue;
            var mNewValue = (DataTemplate)newValue;

            if (mOldValue != mNewValue) { BuildSlider(mBindable, itemHeaderTemplate: mNewValue); }
        }
        #endregion

        #region BindableProperty: ItemsSource.
        public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create(nameof(ItemsSource), typeof(IEnumerable), typeof(OptionsSliderView), propertyChanged: ItemsSourcePropertyChanged, defaultValue: null);
        public IEnumerable ItemsSource
        {
            get { return (IEnumerable)GetValue(ItemsSourceProperty); }
            set { SetValue(ItemsSourceProperty, value); }
        }

        private static void ItemsSourcePropertyChanged(BindableObject bindable, object oldValue, object newValue)
        {
            var mBindable = (OptionsSliderView)bindable;
            var mOldValue = (IEnumerable)oldValue;
            var mNewValue = (IEnumerable)newValue;

            if (mOldValue != mNewValue) { BuildSlider(mBindable, itemsSource: mNewValue); }
        }
        #endregion
...

    private static void BuildSlider(
            OptionsSliderView optionsSliderView,
            DataTemplate itemTemplate = null,
            DataTemplate itemHeaderTemplate = null,
            IEnumerable itemsSource = null,
            ScreenPosition screenOrigin = ScreenPosition.Right,
            int itemsPerRow = 0,
            Thickness borderSize = new Thickness())
        {
            if (itemTemplate != null && itemTemplate != optionsSliderView.ItemTemplate) { optionsSliderView.ItemTemplate = itemTemplate; }
            if (itemHeaderTemplate != null && itemHeaderTemplate != optionsSliderView.ItemHeaderTemplate) { optionsSliderView.ItemHeaderTemplate = itemHeaderTemplate; }
            if (itemsSource != null && itemsSource != optionsSliderView.ItemsSource) { optionsSliderView.ItemsSource = itemsSource; }

            if (optionsSliderView.Parent != null)
            {
                if (optionsSliderView.contentGrid == null) { optionsSliderView.contentGrid = new Grid(); }

                var gridRef = optionsSliderView.contentGrid;
                gridRef.Children.Clear();
                gridRef.RowDefinitions = new RowDefinitionCollection();
                gridRef.ColumnDefinitions = new ColumnDefinitionCollection();
                gridRef.BackgroundColor = optionsSliderView.BorderColor;
                gridRef.Padding = optionsSliderView.BorderSize;
                gridRef.ColumnSpacing = 0;
                gridRef.RowSpacing = 0;

// How should I do the gridRef.Children.Add here?;
                }
            }

Example usage:

<ContentPage
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:d="http://xamarin.com/schemas/2014/forms/design"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:views="clr-namespace:ControlComponentExcercise.CustomViews"
    mc:Ignorable="d"
    x:Class="ControlComponentExcercise.MainPage">
    <RelativeLayout>
        <StackLayout Orientation="Vertical"
                     BackgroundColor="Gray"
                     Padding="20"
                     RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}"
                     RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}">
            <StackLayout Orientation="Horizontal">
                <Switch PropertyChanged="Switch_PropertyChanged" IsToggled="True"/>
                <Label Text="Should animate" />
            </StackLayout>
            <Button Text="Change Border colors" Clicked="Button_Clicked"></Button>
            <Label Text="Border Size" />
            <Slider ValueChanged="Slider_ValueChanged" Maximum="10" Minimum="0"  />
            <Button Text="Add/Remove Header Template" Clicked="Button_Clicked"></Button>
            <Button Text="Alternate Screen Origin" Clicked="Button_Clicked"></Button>
        </StackLayout>
        <views:OptionsSliderView BackgroundColor="Aquamarine"
                                 BorderColor="Purple"
                                 Animate="True"
                                 ScreenOrigin="Right"
                                 BorderSize="10">
            <views:OptionsSliderView.ItemsSource>
                <x:Array Type="{x:Type x:String}">
                    <x:String>Item 1</x:String>
                    <x:String>Item 2</x:String>
                    <x:String>Item 3</x:String>
                    <x:String>Item 4</x:String>
                    <x:String>Item 5</x:String>
                </x:Array>
            </views:OptionsSliderView.ItemsSource>
            <views:OptionsSliderView.ItemTemplate>
                <DataTemplate x:DataType="x:String">
                    <Label Text="."/>
                </DataTemplate>
            </views:OptionsSliderView.ItemTemplate>
            <views:OptionsSliderView.ItemHeaderTemplate>
                <DataTemplate x:DataType="x:String">
                    <Label  BackgroundColor="AliceBlue" Text="."/>
                </DataTemplate>
            </views:OptionsSliderView.ItemHeaderTemplate>
        </views:OptionsSliderView>
    </RelativeLayout>
</ContentPage>

Entry vertical text alignment inconsistency between iOS and Android

$
0
0

So I took a closer look on the Entry on my app and discovered that the placeholders are not vertically centered the same on Android and iOS. Trying to correct it on android inside a custom renderer:

Android.Widget.EditText editText = Control // property of the EntryRenderer
editText.Gravity = Android.Views.GravityFlags.CenterVertical;

I found that I could successfully set the native android instance of Entry to different "Gravity" enumerations. But the fact is that the CenterVertical simply don't place the placeholder text the same as on iOS.
Is there anyway around this inconsistency?

On iOS:
Where a line is drawn (horizontally) across the Entry cutting it half. This line cuts the placeholder in half. So the top of a P character is as far to the top of the Entry as the bottom of P is to the bottom of the Entry.

On Android:
The top of the P letter in the placeholder is more near the top of the Entry - than what the bottom of it are to bottom of Entry.

Viewing all 91519 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>