I created MainWindowViewModel and use the RelayCommand class here to ... pass the command. Am I breaking any recommendations by having a MenuItem from MainWindow to bind its command to a property of this view model?
No, exactly where you add commands.
This action, with which I associate the MenuItem command, will instantiate a new ViewModel and a new view and display it. Again, is this normal in the context of MVVM?
No need to know how to instantiate a new view; what a viewing task. The specifics of how to do this depends on how you display this new view - it can be as simple as having a ContentPresenter in the view associated with a property in the view model, so when you set the property (and raise the PropertyChanged) ContentPresenter displays a new object with the corresponding DataTemplate.
Everything becomes a little strange if “create a new view” means “open a new window”. There is no particularly elegant way to do this, especially if you want the new window to be a modal dialog. One way is to add an event handler to the view code that listens for PropertyChanged in the view model; when the property of the subview model is set, the code in the view creates and displays a new window.
My MainWindow will be a kind of dashboard, and I will have more than one model attached to this dashboard. Should I just transfer all of these models into one view model?
Of course. This is a very common picture. It is not at all uncommon, for example, to set the visible property of a collection and associate with it some ItemControl; The view will automatically create views for each view model that you have embedded in this collection. Again, the specific implementation really depends on your application.
Robert rossney
source share