Property Setter set multiple times - as many times as a bound subview mentioning it is opened.

TobyKTobyK GBMember ✭✭✭
edited January 8 in Xamarin.Forms

Hi guys, I have found an issue....

I have a viewmodel with a ToSection property on it. Both Getter and setter etc. the Viewmodel is bound to my Main View. In my main view I have the command bound that opens a new subview that has the ToSection property mentioned in the xaml - this property is not used by anything else. I set the subview bindingcontext to 'this' - being the viewmodel and I'm pusing it onto the nav stack as follows:

                ToSection = null; // Reset To Section Picker.
                await parent.Navigator.PushAsync(
                    new WmsJobItemsToView
                    {
                        BindingContext = this,
                        Title = string.Format("{0} ({1})", e as string, Items.Where(o => o.Pending > 0).Sum(o => o.Pending))
                    });

However, everytime I press the button to open the subview and then set the ToSection property its setter is being called as many times as I've opened the subview - like it isn't releasing the first one when it is popped off the stack? What am I missing?

Best Answer

  • TobyKTobyK GB ✭✭✭
    Accepted Answer

    I've actually solved the issue. It was down to the BindingContext being 'this'.... I created a new ViewModel for the view containing the ToSection property and the Command that was needed - and now I'm not getting the ToSection property being set multiple times as I create new instances of both view and model when pushing and popping it as normal.

    Thanks @LandLu

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    Could you please post a whole sample to help us reproduce your issue? Without that, we can't detect what problem are you facing.

  • TobyKTobyK GBMember ✭✭✭
    Accepted Answer

    I've actually solved the issue. It was down to the BindingContext being 'this'.... I created a new ViewModel for the view containing the ToSection property and the Command that was needed - and now I'm not getting the ToSection property being set multiple times as I create new instances of both view and model when pushing and popping it as normal.

    Thanks @LandLu

Sign In or Register to comment.