Issue
So when making a custom renderer , you do most of your work inside the overriden OnElementChanged() function.I want to make a custom renderer for the Xamarin.Forms.Picker control:
protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
what is here the difference between e.NewElement and Control?The second one seems to be inherited from ViewRenderer(PickerRenderer in my case).I also don't quite understand what e.OldElement does, maybe the reference to my last custom Picker? Thanks.
Solution
Control(this.Control) is the PLATFORM control. E.g. on Android, it is a subclass ofAndroid.Views.View.Element(this.Element) refers to the XAMARIN FORMS cross-platform element/view. It is a subclass ofXamarin.Forms.View.e.NewElementis always identical tothis.Element.e.OldElementis the previous value that was attached to this custom renderer. It will benullwhen the renderer is created.- When the renderer is disposed,
OnElementChangedmight be called again, withe.OldElementbeing the XF element that is going away. In this case,e.NewElementisnull.
IMPORTANT: In OnElementChanged, always check whether e.NewElement is null. If it is, do nothing. (Or call any "cleanup" code, if you need to do something when "going away"/disposing.)
Answered By - ToolmakerSteve
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.