I am developing a fairly simple WPF application to display a hierarchy of objects plus the detail of a selected object using the UserControl wrapping a TreeView in the left pane (a tree control) and another UserControl wrapping a ListView / GridView on the right (a part control).
Tree management uses MVVM after this article by Josh Smith quite closely and has several types of ViewModel, all of which are based on the same basic type, TreeViewModel . The main window is configured using the MainWindowViewModel , as in this article by Josh Smith , and provides the TreeViewModel used to populate the first generation of the tree.
However, when I want to populate the details panel on the right, I have a problem that the SelectedItem of the tree control is obtained from the TreeViewModel when I need a completely different type of ViewModel for the details panel, which will expand the object into the property / value table using reflection.
So the questions are:
Is it possible for MainWindowViewModel display a TreeViewModel for a control tree? I believe the answer here is yes, but I am open to suggestions to the contrary.
How to select the selected item in the control tree with the right-click ViewModel for the details pane? One option, apparently, is that MainWindowViewModel keeps track of the selected item in the tree and performs the adaptation, exposing it as another property, but I'm not sure if there is a better solution.
I am new to WPF and the MVVM pattern, so please excuse the rather basic point of the question. I did a small part of reading against the background of the template, looked at some sample applications, etc., but I canβt find anything concrete enough so that I can be sure of the answer. I also understand that MVVM can be excessive for the application, it's simple, but I use it partially as a training exercise.
source share