I'm working on figuring out mvvmcross and if I can use it for an iPhone (and eventually iPad and Android) app I'm going to develop. The MVVM pattern is really powerful and works great for me, but I have several views where I need to add a navigation control that will allow the user to jump to several different other views and I'm wondering what's the best way to do it.
Right now, I've created a NavigationControlViewModel
which exposes a collection of NavigationLinkViewModel
which have a link text property and a command that will show the appropriate view. But to add this to a view for, say, MyViewModel
is a little tricky. Right now what I've done is add the NavigationControlViewModel
to MyViewModel
so that I can bind it in MyView
:
private NavigationControlViewModel _nav;
public NavigationControlViewModel Navigation {
get {
_nav = _nav ?? new NavigationControlViewModel (Mvx.Resolve<INavigationService> ());
return _nav;
}
}
This works, but doesn't seem as nicely contained as I'd like to be. I still need to add controls to MyView
for the NavigationControlViewModel
and then add it to every other view that needs it (as well as adding it to their view models).
What would be the best practice for handling this sort of thing in iOS and MVVM?
I've seen the video on using a split view, but I'm not sure if that's the best approach. I need a vertical split and I only need it on some views, not every view.