Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Inherited renderer, OnElementPropertyChanged implementation

$
0
0

I often see this kind of overrides on custom renderer that inherits from XF renderer and I am thinking it is due to developers not putting too much thought into the function:

    protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        base.OnElementPropertyChanged(sender, e); // calls the base method every time

        if (e.PropertyName == .. // custom view properties come after the base method is called

That seems like a waste of resources to me and the base should instead be called only if the custom renderer doesn't handle it:

    protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        if (e.PropertyName == "MyPropertyName1")
        {
            // do something here
        }
        else if (e.PropertyName == "MyPropertyName2")
        {
             // do something here
        }
        else
        {
            base.OnElementPropertyChanged(sender, e);
        }
    }

Is there a specific reason why the Forms base renderer's OnElementPropertyChanged should always be called or is the latter the correct way of doing this?


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>