When we will try to navigate between screens we will use INavigationService.NavigateToViewModel<TDestionViewModel>. This will work great.
Navigation.NavigateToViewModel<MyFooPageViewModel>();
Each ViewModel need to implement the Screen class. This will give access to all the features that we need in the view mode. But what about sending data from one view to another. The method NavigateToViewModel can accept an parameter of type object.Navigation.NavigateToViewModel<MyFooPageViewModel>(“some data”);
Looks good but you will be surprised when you will try to get this data in your destination ViewModel. You will not be able to find this data anywhere. To be able to access this parameter, you’ll need to define a parameter in your destination ViewModel named Parameter, with the same time as your parameter that you specify when you call the navigation method.
public class MyFooViewModel : Screen
{
public string Parameter {
get {...}
set {...}
...
}
Don't forget that the Parameter property is set after the ViewModel is created. Because of this, in the setter you should process the input data. Enjoy!
0 comments:
Post a Comment