Reputation: 5726
I have PageA + ViewModelA, and PageB + ViewModelB.
From A i'm calling PushAsync(B), editing some data, and calling PopAsync().
So now B becomes closed, and user returns to A.
But in B user changed some state, that should be update on A. What is the correct way to notify A to update state (and it would be better to have access to ViewModelB).
Approaches:
1. In B call PopAsync(), from NavigationStack get ViewModelA and manually trigger some update method
2. [doesn't work for me] In A call PushAsync(B) and wait until B becomes closed, so after that perform update with access to VMB (PushAsync doesn't lock A, so this approach doesn't work)
Seems both of these approaches are incorrect.
Upvotes: 0
Views: 250
Reputation: 6142
Normally in a MVVM environment, when you need to 'signal' changes to other ViewModels, you use a Messaging system. Depending on the MVVM framework you'll need to look at what class is available for this.
In xamarin forms you'll have the messaging center https://developer.xamarin.com/guides/cross-platform/xamarin-forms/messaging-center/
Upvotes: 1