I have one ViewModel and two Views. How can I navigate to View2 from ViewModel. I read somewhere that we need to use PRISM, for opening multiple Views from ViewModel in Silverlight. Is there any alternative for PRISM?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Ideally you do not want to use view logic in your viewmodel. Your viewmodel should not know anything about the view. It would be a better idea for your viewmodel to set a property letting the view know it’s time to navigate.
Here’s an example:
ViewModel:
View:
Use a
DataTriggerwithBindingproperty set to theDoneDoingStuffproperty from your viewmodel, and theValueproperty set to “True”. TheDataTriggerwill trigger whenDoneDoingStufffrom your viewmodel is set to true.Now you need a trigger action to navigate. Use
HyperlinkActionwith theNavigateUriproperty set to the page you’re navigating to.Be sure to have System.Windows.Interactivity, System.Windows.Controls.Navigation, and Microsoft.Expression.Interactions assemblies in your references.
At first, this might seem to be too much, but your view logic is now where it needs to be.