I'm getting beyond a simple MVVM program now, and I'd just like to sense check my current architecture and makes sure I'm going down the right path here.
Everything is structured around screens, and these screens have a kind of "tree" breakdown. On the top level there's a home screen, and you can drill down through related screens.
I've made a simplified example, an application that tracks employees for companies. It has three "screens".
- CompanyOverviewScreen, lets you see all the companies you have. Click to go to the below:
- EmployeeTrackerScreen, lets you see all the employees in this company and their location. Click to go to the below:
- EmployeeScreen, let's you see information about an employee.
So the screens open up like a tree:
Question 1: Where should these screen view models be created and stored? Should they be created and stored in one place above everything, or should the EmployeeTrackerScreen ViewModel create the EmployeeScreen ViewModel and store it as a collection property?
I'm also using shared ViewModels that don't have views for the data and UI properties in these screens where they are displaying a collection of items. For example, the EmployeeTrackerScreenView has an ItemsCollection to directly bind to an ObservableCollection that are stored as properties in the EmployeeTrackerScreenViewModel.
Here's a quick sketch of how it's structured:
So the EmployeeTrackerScreenView looks like this:
<UserControl x:Class="Project.EmployeeTrackerScreenView >
<DockPanel>
<StackPanel DockPanel.Dock="Top">
<Label Content="{Binding CorporationViweModel.Name}" />
<Label Content=" has " />
<Label Content="{Binding CorporationViweModel.NumberOfEmployees}" />
</StackPanel>
<ScrollViewer>
<ItemsControl ItemsSource="{Binding ObsvCollectionOfEmployeeViewModels}" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Label Content="{Binding EmployeeModel.Name}"/>
<Label Content="is"/>
<Label Content="{Binding EmployeeModel.Location}"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</DockPanel>
</UserControl>
Question 2 Is in line with MVVM patterns? Am I going about it the right way?
I'd love some comments on how I'm structuring things, perhaps some advice on whether I'm going about it in a sensible way. I hope the question provides enough information and is appropriate. I'm new to this kind of software design, I've always made smaller apps in the past, so I'm inexperienced in proper architecture.
I've been using Caliburn Micro MVVM framework, in WPF if that's useful to know.