How can I open another view in WPF MVVM using click handlers and commands? (Is my solution reasonable?)

前端 未结 2 1260
梦毁少年i
梦毁少年i 2020-12-20 05:33

I am writing a WPF application that has two windows.

I have a MainWindowViewModel that holds two more view models: AllTagsViewModel and

2条回答
  •  再見小時候
    2020-12-20 06:34

    Your approach has the possibility of creating a PlotWindow without the existing PlotViewModel if you use the CanExecute of your CreatePlotViewModelCommand.

    To avoid that problem I would bind the MainWindowView to the PlotViewModel property defined inside the MainWindowViewModel. That way you will get informed once it changes and you can set up a template creating the corresponding view. The ViewModels could than easily be created using a command and the view will only be created if a ViewModel exists.

提交回复
热议问题