One year ago, I discovered the WPF technology and I developed a little application, as first experiment, to compare the content of two different directories. The content of each directory is shown in a different DataGrid. At that time, I didn't develop the application using MVVM pattern, because it was only an experiment, not so good, but it worked.
Now that I've much more experience with WPF and with the design patterns, I'm not so proud of that work, and I want to rewrite the application, improving it and following the recommended MVVM pattern.
Actually, I designed the application in this way:
- the MainModel, with the main common algorithm.
- the MainView is the unique view of the application with the datagrids where I can show the results of my algorithms.
- a MainViewModel, that it will take care of handling the connection between other two ViewModels, the MainModel and the MainView.
- One ViewModel for each DataGrid. In this way, I'll separate the behavior and the data of the two DataGrids.
The MainModel contains the main algorithm used to search the files in a given directory, like this:
public class MainModel
{
public MainModel()
{}
public List<Results> GetFiles(string directoryPath)
}
The MainViewModel will instantiate an object for each ViewModel (I have a ViewModel for each datagrid), using some properties to do it:
public class MainViewModel
{
public MainViewModel()
{
FirstViewModel = new ViewModelDG1();
SecondViewModel = new ViewModelDG2();
}
public ViewModelDG1 FirstViewModel
{get;set;}
public ViewModelDG2 SecondViewModel
{get;set;}
}
I wanted to apply a design pattern to help me manage the application, like a Factory Method or Builder, or a Template Method, but I think they're not suitable for my application for the different usages/conditions of those design patterns.
I'm not so sure of this design, I don't know if this a is correct implementation of the MVVM pattern and if it promotes a loose coupling and high cohesion. Can you help me in the design? Is mine a correct implementation of the MVVM? If not, then what is the correct one? What are your opinions?
Thank you.