Search code examples
xamarinxamarin.formsuwprenderer

Custom renderer for Grid


I am trying to create a custom Renderer in UWP for Xamarin.Forms.Grid, but I can't figure out the type-parameters for ViewRenderer<TElement, TNativeElement> can anybody help me?

I tried with ViewRenderer<Grid, FrameworkElement> but Control is null


Solution

  • You need to set the Control by overriding OnElementChanged So Implement your view renderer by inheriting like you did above:

    ViewRenderer<Xamarin.Forms.Grid, XControl.Grid>
    

    then override OnElementChanged:

    using XControl = Windows.UI.Xaml.Controls;
    .
    .
    .
    protected override void OnElementChanged(ElementChangedEventArgs<XControl.Grid> e)
    {
       if (e.NewElement != null)
       {
          if (Control == null)
          {
             var container = new XControl.Grid();
             SetNativeControl( container);
          }
       }
    }