Using Catel - Architecture

Mar 26, 2012 at 6:56 PM


I am working on a simple application and trying to use the goodies from the Catel framework.

What I need to do is a following:

  • Display a GUI with some settings the user can change
  • When the user click a start button, collect the data and use it in the execution of some code.
  • When the user closes the application I want to save the settings. When the application opens I want to load settings if they exist already.
  • Some actions from the Main window should cause the child View/ViewModels to refresh

I want to use MVVM and Catel offers many helpful classes. Unfortunately, I am relatively new to MVVM and the framework and a little at loss.

What I did (and hopefully is not too far off) is:

  • Create 2 main model classes based on SaveableDataObjectBase (and some support model classes used in the main model classes)
  • I implemented 2 ViewModels (one for each main model) that instantiate an instance of the model class
    • VM contains additional properties and commands
    • Some of the "additional properties" are for example, a list of possible selection values that go-to/selected-by the model
  • I implemented 2 View classes (user controls) that request corresponding VM classes
  • Implemented a main View and ViewModel
    • View contains the 2 views from above and some menu etc and the start/stop and cancel buttons
    • VM contains command

What would be a good approach to get the data from the VMs?

I guess I can create the Model classes in application startup register them in IOC and then get them in the VMs (resolve) then also get the same instances in the main VM and when the application shut down save them.

I'll be happy to hear how something like this is "best" implemented using features of Catel.



Mar 26, 2012 at 9:40 PM

It seems that you have already done quite a good job. Normally, you have a repository or a service where you can get the models from. Then then view model can retrieve this repository or service via the GetService<> method of the view model, and interact with it.

You might want to take a look at the Person application (can be found in the examples) which shows how to use a repository of users and how to interact with modal popups and the same models.

Mar 27, 2012 at 7:05 PM

I am not finding examples.  How do I find them? 

Mar 27, 2012 at 7:07 PM

See It is a repository for all the catel examples.

You can also find documentation about all examples:

Examples docs

Mar 28, 2012 at 1:00 AM

Hi Hugh,

Note that you have to download sources ("Source Code" tab) as there are no packaged zips or the likes in the "Download" section

(Took me a while to get that ;-)

Thanks Greet for the pointers.