Different behavior of SetNativeControl in PageRenderer

282 Views Asked by At

I was using PageRenderer for native UWP (Universal Windows Platform) but it behaved weird which I didn't expect. I used following class to render a native page MyUWP to load in place of a Xamarin.Forms page

class MyUWPRenderer : PageRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
    {
        base.OnElementChanged(e);


        if (e.OldElement != null || Element == null)
        {
            return;
        }
        try
        {
            // **** Element.Content = null;
            SetNativeControl(new MyUWP());
        }
        catch (Exception ex)
        { 
        } 
    }
}

If I don't use Element.Content = null; in above code, both pages (Native and Xamarin.Forms) will be render on top of one another. So, I had to first set the Content to null to make native page visible.

Is there any reason behind it or am I understanding wrong? The above similar code works in Xamarin.Android project very well.

0

There are 0 best solutions below