rid00z / FreshMvvm

FreshMvvm is a super light Mvvm Framework designed specifically for Xamarin.Forms. It's designed to be Easy, Simple and Flexible.
Apache License 2.0
596 stars 172 forks source link

ViewModel reset prior to View disappearing #303

Open munkii opened 4 years ago

munkii commented 4 years ago

When we call PopPageModel with animate=true the input controls on the View temporarily appear as zero.

For example if we bind a Entry to a double property

<Entry Text="{Binding TemperatureValue}"></Entry>

Then call

await this.CoreMethods.PopPageModel(newTemperature, true, true);

The text box resets to blank and that is visible for about 0.5 seconds before the View disappears. This is because the BindingContext gets set to Null prior to the View disappearing.

If I remove the binding in BindingContextChanged then the TextBox\Entry field continues to display data as I'd expect but I assume that isn't the expected approach.

protected override void OnBindingContextChanged()
{
    if (this.BindingContext == null)
    {
        this.txtTemperature.RemoveBinding(SfNumericTextBox.ValueProperty);
    }

    base.OnBindingContextChanged();
}

I assume this is By Design. Is there a suggested approach to prevent the momentary flash of an unbound View?

UPDATE I have also asked this question StackOverflow, https://stackoverflow.com/questions/60171744/freshmvvm-and-resetting-vm-before-popping-modal

nexxuno commented 4 years ago

I'm struggling with this problem too. It hurts badly in my scenario because I have property bound two way with a converter on it and the ConvertBack method gets called with null values and crashes. I could workaround this but then my viewmodel would receive a bad value to persist so that's not an option. @rid00z this looks like a big bug to go unnoticed for so long, what are we missing here?

munkii commented 4 years ago

@nexxuno I do think it is a bug and it's good to hear i'm not the only one. I'd love to get some input from @rid00z but in the meantime I have updated the stackoverflow question with the solution we have gone with, https://stackoverflow.com/questions/60171744/freshmvvm-and-resetting-vm-before-popping-modal/61118083#61118083