Hello,
I Have searched many ways to pass the data from one View to another, but the solutions that are suggested is wrong because you break the MVVM pattern (e.g pass data by constructorse e.t.c)
You can create Init(data)
in the BaseViewModel
which is extended by other viewmodels
public abstract class BaseViewModel
{
public abstract void initData(string data);
}
Then when you bind the viewmodel, you can set the data by initData
method.
public MainPage(string senddata)
{
InitializeComponent();
MyViewModel myViewModel= new MyViewModel();
myViewModel.initData(senddata);
BindingContext = myViewModel;
}
Or you can use Constructor injection as well.
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.