With Prism, it is important to use the plural form of ViewModels for your folder/namespace structure. Prism uses that by convention when auto wiring the view models.
We have two forms currently. For each form I have defined a navigation view, a form view, and a view model.
Transaction Form Module
In our module, we register the navigation views. We also register the form views and optionally navigate to our default page.
The views will all be UserControls. They are loaded into the regions we defined on the Shell view.
In Prism, we wire up the view model in the namespace area of the views. We must make sure the define namespaces for Prism, the prism library and vm, the location of the view models.
In the account view, I am showing a data grid which is auto generated based on the data bound to the property, Records.
Account View Model
The view models inherit from BindableBase. This gives the class the SetProperty method. It enables the property changed event which is used by the view binding.
The view models also implement the INavigationAware interface. This enables the view to be navigated to.
I use dependency injection to set a reference to the AccountService. When the account is navigated to the Records property is populated with the accounts using the account service.
Run the Program!
When all the code we have reviewed runs we get to view our account page.
The complete source code for this project is located on Github.
If you found this article helpful use the tweet button below to spread the word. Thank you.