I'm trying to find an elegant way to locate views for viewmodel subclasses in viewmodel first approach. I would like to use a custom view if it is available for a given viewmodel (which CM does just fine), but if not, then locate the view for the viewmodel's
base class and use that instead (which CM doesn't do).
As an example, let's say that I have a ViewModel, named 'MyDataViewModel', which supports multiple contexts that are bound by CM using conventions. For some data, I need to use a subclass of 'MyDataViewModel', e.g. 'ImageDataViewModel', that allows me to
replace some of these views easily. Many of the views do not need to be customized at all, though. How should I accomplish this:
MyApp.ViewModels.MyDataViewModel + Context1 => MyApp.Views.MyData.Context1
MyApp.ViewModels.MyDataViewModel + Context2 => MyApp.Views.MyData.Context2
MyApp.ViewModels.MyImageViewModel + Context1 => MyApp.Views.MyImage.Context1
MyApp.ViewModels.MyImageViewModel + Context2 => MyApp.Views.MyData.Context2 (i.e. use the base class view since the view MyApp.Views.MyImage.Context2 doesn't exist).
Currently, CM won't find a view for the viewmodel and context on the last line. Also, it is not very easy to include the base class view in the 'derived' view, due to CM action bindings and other conventions used in the base class view. I've so far tried:
- subclassing from the base view (XAML wouldn't allow),
- including the base class view in the more specialized view (conventions were not applied), and
- creating a ContentControl for displaying the base view and applying the CM binding in code (couldn't get this to work either, controls from the base view didn't come visible).
Any suggestions? Thanks,