Renderer - how to access properties from parent?

flix101flix101 USMember ✭✭

Hi,

I have a PageRenderer class. In the parent one I have a property. What I want is to set this property from the Renderer class.
One option might be, making this prop. static and access it by using
ParentClass.prop = value;

But that would not ensure the instance from the right parent class will be used, right?
Not I would go for a solution like:

using the OnElementChanged method to get an the parent page.

protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Page> e)
        {
        _myPrivatePage = (NameOfParentClass)e.NewElement;
            base.OnElementChanged(e);
...
    }

Is that the way to go?
Unforunately I can't access the property by using _mypPrivatePage.property, after using the above method.

Answers

  • JohnHardmanJohnHardman GBUniversity ✭✭✭✭✭

    @flix101

    By "I can't access the property", do you mean that _myPrivatePage is null?

    You probably want to:

    • Swap the order of the two lines in your OnElementChanged
    • Use Element instead of e.NewElement
Sign In or Register to comment.