Exception is thrown while showing a page with a Switch in a <StackLayout IsVisible="false"/>
StackTrace:
at Windows.UI.Xaml.VisualStateManager.GetVisualStateGroups(FrameworkElement obj)
at Xamarin.Forms.Platform.UWP.SwitchRenderer.UpdateOnColor()
at Xamarin.Forms.Platform.UWP.SwitchRenderer.OnControlLoaded(Object sender, RoutedEventArgs e)
Message:
System.ArgumentException: Falscher Parameter.
element
at Windows.UI.Xaml.VisualStateManager.GetVisualStateGroups(FrameworkElement obj)
at Xamarin.Forms.Platform.UWP.SwitchRenderer.UpdateOnColor()
at Xamarin.Forms.Platform.UWP.SwitchRenderer.OnControlLoaded(Object sender, RoutedEventArgs e)
Caused by #4883, probably
This one is a real blocker. It would be very much appreciated if this could be fixed in the next release..
For me the problem seems to be independent of whether there is a StackLayout. My <
Switch>
was set IsVisible=false, and I got exactly the crash described here. Changing it to true fixed the problem (though my UI looked weird). But setting IsVisible to false in the code of the handler for Toggle gave me a workaround.
There's a discussion on the forums regarding the issue, the only work-around appears to be writing a custom renderer that overrides OnElementChanged() and OnElementPropertyChanged() to avoid the call to UpdateOnColor()
https://forums.xamarin.com/discussion/151252/switch-crashing-uwp-app-post-upgrade-to-xf-3-6
Same for me, but 3.5 works fine https://github.com/xamarin/Xamarin.Forms/pull/4883#discussion_r267342643
also getting this error
I think this was fixed by PR #5633; the error goes away for my UWP project when I update to the latest Xamarin.Forms 3.6.0 NuGet package (tested with 3.6.0.344457).
As @vividos says it seems to be fixed, it is working for me as well ( with version 3.6.0.344457)
closed by #5633
It's back! I'm getting the same error after updating my UWP projects to 4.5
System.NullReferenceException: Object reference not set to an instance of an object.
at Xamarin.Forms.Platform.UWP.SwitchRenderer.UpdateOnColor()
at Xamarin.Forms.Platform.UWP.SwitchRenderer.OnControlLoaded(Object sender, RoutedEventArgs e)
Most helpful comment
This one is a real blocker. It would be very much appreciated if this could be fixed in the next release..