Reputation: 594
In MVVM pattern ViewModel should not have any knowledge about View (and its dependencies).
Prism (MVVM library) for Xamarin.Forms has dependency on Xamarin.Forms so it breaks above rule although prism team claims to fulfill Microsoft patterns & practices. Another libraries does not have such dependencies (for example mvvmcross, freshmvvm)
How to understand it?
EDIT:
Upvotes: 0
Views: 269
Reputation: 2617
Interesting point, however not really Accurate.
MVVM as you said is to separate the ViewModel from the View. So what would break the pattern is if we have an instance of the View inside the ViewModel and you start controlling it directly from the viewmodel that would break the MVVM pattern.
Having a library that the view depends on inside the viewmodel will not break the mvvm pattern. Consider the case of having a Json Library in both sides. However, it would limit how cross platform our solution would be. So in your case you will not be able to share your viewmodels with other platforms than Xamarin (e.g. WPF).
If you really want to make use of Prism and in the same time have the same ViewModels for a WPF, then in Theory this would work:
Notes
BindingContext = _viewmodel;
in the codebehind or in Xaml. Upvotes: 1
Reputation: 10863
ad 1: given the views are somewhat similar, migrating the view models should be easy, perhaps a matter of copy-and-paste-plus-tidying-up
ad 2: I'd be really surprised if that happened, the other way round is more likely, see this comment on github
Upvotes: 0