My attempts at trying to stick with the MVVM design pattern has left me spinning in my tracks. I have a view that is a pick list of site locations. I have a viewmodel that the view gets its data context from and I've bound some items to it with buttons and such (yay!).
Now I'm trying to switch the current view from a button click from within the view.
By clicking on the "start maintenance" button I would like to switch the view to another view with a different viewmodel.
So I know MVVM is just a design pattern and there seems to be a bajillion different ways of implementing navigation with MVVM. But the majority of these solutions I've seen point to having a main navigation pane and that is not what i am intending to do.
I plan on now trying to use a viewmodellocator with MVVM light messenger pattern to try and get my views to change. But after spending the past 3 days trying to shoehorn this thing to work, I'm growing desperate. Are there any other suggestions on how to implement this? I do like Sheridan's answer to a similar post:WPF MVVM navigate views because it avoids using a toolkit/framework. But I think the answer was perhaps too vague for me and I couldn't implement it because I didn't understand how to change the views (Sheridan's custom relay message was hard to follow as a novice).
Help please you Internet Denizens! :) If you could point me to any examples that would appreciated as well!
ContentControl
and bind it'sContent
to aSelectedViewModel
, and then use implicit DataTemplates to tell WPF how to draw each ViewModel. I have a basic example with no 3rd party libraries on my blog here if you're interested : Navigation with MVVM – RachelContentControl
there, and the default.Content
property would be your Grid. When you click on the button, the.Content
would change to some other View. If you want the whole window to change, you may want to look into using a messaging system to pass broadcast a message, and have your child VM subscribe to those messages. – Rachel