Hi,
I'm using a custom FrameRenderer in my UWP project to style frames (corner radius and color). When I scroll a bit back and forth, the app crashes with a System.ArgumentException: Value does not fall within the expected range. It's the call to base.OnElementChanged(e);
that causes it.
I can of course put that in a try/catch, but then some items in my list will disappear. They return on orientation change of the device, but not after a normal refresh of the FlowListView I'm using.
Any ideas? I'm on Xamarin Forms 2.5.1.444934.
Here's the custom FrameRenderer:
class ExtendedFrameRenderer : FrameRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Frame> e)
{
base.OnElementChanged(e);
if (Control != null)
{
var frame = e.NewElement;
double cornerRadius = frame.CornerRadius;
Windows.UI.Color frameBG = Windows.UI.Color.FromArgb(
(byte)(frame.BackgroundColor.A * 255),
(byte)(frame.BackgroundColor.R * 255),
(byte)(frame.BackgroundColor.G * 255),
(byte)(frame.BackgroundColor.B * 255));
Control.CornerRadius = new Windows.UI.Xaml.CornerRadius(cornerRadius);
Control.Background = new SolidColorBrush(frameBG);
frame.BackgroundColor = Xamarin.Forms.Color.Transparent;
}
}
}
Full error stack:
System.ArgumentException
HResult=0x80070057
Message=Value does not fall within the expected range.
Source=Windows
StackTrace:
at Windows.UI.Xaml.Controls.Border.put_Child(UIElement value)
at Xamarin.Forms.Platform.UWP.FrameRenderer.PackChild()
at Xamarin.Forms.Platform.UWP.FrameRenderer.OnElementChanged(ElementChangedEventArgs`1 e)
at MyApp.UWP.Helpers.ExtendedFrameRenderer.OnElementChanged(ElementChangedEventArgs`1 e) in C:\Users\me\Source\Workspaces\MySol\MyApp\MyApp.UWP\Helpers\ExtendedFrameRenderer.cs:line 26
at Xamarin.Forms.Platform.UWP.VisualElementRenderer`2.SetElement(VisualElement element)
at Xamarin.Forms.Platform.UWP.Platform.CreateRenderer(VisualElement element)
at Xamarin.Forms.Platform.UWP.VisualElementPackager.OnChildAdded(Object sender, ElementEventArgs e)
at Xamarin.Forms.Platform.UWP.VisualElementPackager.Load()
at Xamarin.Forms.Platform.UWP.VisualElementRenderer`2.SetElement(VisualElement element)
at Xamarin.Forms.Platform.UWP.Platform.CreateRenderer(VisualElement element)
at Xamarin.Forms.Platform.UWP.VisualElementPackager.OnChildAdded(Object sender, ElementEventArgs e)
at Xamarin.Forms.Platform.UWP.VisualElementPackager.Load()
at Xamarin.Forms.Platform.UWP.VisualElementRenderer`2.SetElement(VisualElement element)
at Xamarin.Forms.Platform.UWP.Platform.CreateRenderer(VisualElement element)
at Xamarin.Forms.Platform.UWP.ViewToRendererConverter.WrapperControl..ctor(View view)
at Xamarin.Forms.Platform.UWP.ViewToRendererConverter.Convert(Object value, Type targetType, Object parameter, String language)