Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation MVVM

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. My page

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!

like image 911
Stunna Avatar asked Oct 31 '22 19:10

Stunna


1 Answers

A big thank you to Rachel! I created a mainviewmodel that instantiates the other view models in my app. Then I used MVVM light to send a message using a template of a generic object to stuff the message between the models which then allowed me to handle the message in my main view model and switch the viewmodel context!

Thanks for all the help!

like image 95
Stunna Avatar answered Nov 08 '22 06:11

Stunna