How to use validation feature of Catel in User Control which itself does not have a viewmodel

Topics: Questions
May 30, 2013 at 10:55 AM
In my application I have the need for a numerous mount of maintenance (list)windows. So I want to write a sort of base class window for it.

Since I want my layout to be in xaml (showing a grid, buttons and filtering fields is not something I look forward to write in code) I alas can not use inheritance in WPF because visual inheritance is not supported in WPF.

So I want to write a view model base class which incorporates the logic for the list window and a user control which I can put on a WPF (Catel) DataWindow for the common UI stuf. The DataWindow then uses (a subclass of) the ViewModelBase class.

How should I go about to be able to use the default catel stuff like validation in the (bound) fields of the user control whilst the logic resides in the view model of the DataWindow (and therefore mainly in the viewmodebase class)?

I now get an error message that the viewmodel for the user control can not be found. Which is correct, because the view model belongs to the DataWindow. I can't set the view model in the user control itself because I don't know the viewmodel (it's a generic control).

So how can I let the user control on the Data Window connect to the view model of the DataWindow, ensuring that validations on fields in the user control are dealt with in the correct manner?

Hope help can be given :)
Coordinator
Jun 1, 2013 at 10:19 PM
You are free to create your own ViewModelBase class (actually we encourage you to do so so you can always easily add custom logic in afterwards). Because you want advanced control over the views and view models, you should take a look at the naming conventions documentation. If your view models cannot be determined by the naming conventions, you can always override GetViewModelType on the view itself to return the right instance.