Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

What is all this New, Old and Element stuff inside a Custom renderer?

$
0
0

Hi all, I'm building a small library of controls that aren't provided by Xamarin.Forms like Checkboxes and RatingBars. So far they are working well, but I want to know the right way to set up the renderer for them.

Explicitly what is the use of OldElement, NewElement?

Docs only give this template, but I pesonally think that it isn't very instructive:

protected override void OnElementChanged (ElementChangedEventArgs<NativeListView> e)
{
  base.OnElementChanged (e);

  if (Control == null) {
    // Instantiate the native control and assign it to the Control property
  }

  if (e.OldElement != null) {
    // Unsubscribe from event handlers and cleanup any resources
  }

  if (e.NewElement != null) {
    // Configure the control and subscribe to event handlers
  }
}

In which scenarios are OldElement distinct from null and in which is null, and in which is NewElement null or not?

Hope someone could help me to understand.


Viewing all articles
Browse latest Browse all 204402

Trending Articles