Navigate to a View without ViewModel in MvvmCross
-
12-12-2019 - |
Question
My general question: Is there a way to navigate to a View without ViewModel?
In example:
I have an Activity which doesn't include a ViewModel, cause it's displaying only a picture for a short time and disappears afterwards. Now the normal way would be to do a requestNavigate(). But i have no ViewModel to enter there. How can i navigate to this activity?
Thanks for answers!
Solution
My opinion: Yes - you should always use a ViewModel.
On each platform, the mvvmcross framework uses the Type of the ViewModel in order to identify which View to show.
If you don't use a ViewModel, then how will the client apps know what View to show?
If you find you have a lot of these empty ViewModel classes, then you could, of course, always use a ViewModel like:
public class StaticViewModel : BaseViewModel
{
public enum WhichOne
{
AboutPage,
InfoPage,
HelpPage,
// etc
}
public WhichOne WhichPage { get; set; }
public StaticViewModel(string which)
{
WhichPage = (WhichOne) Enum.Parse(typeof(WhichOne), which, false);
}
}
but overall, I don't think this would gain you anything over using one ViewModel per View...