In my application, I'm dealing with an ItemControl
. This itemControl receives an ObservableCollection.
As you can see above, BaseItemViewModel is an abstract class. And when my application is launching, moduleCatalog
loads the modules by discovery.
Each module has a class inherited from BaseItemViewModel
So I can't set the dataTemplates in ItemsControl like this:
<DataTemplate>
<View:GeneralSettingsView/>
</DataTemplate>
<DataTemplate>
<View:AdvancedSettingsView/>
</DataTemplate>
What can I do to show the view from the respective view model if I'm using Module Discovery?
Have you looked at the ItemTemplateSelector property?
For example, create a content selector class:
Create a static resource for it:
And set in the ItemsControl:
And set your datatemplates to the names:
Something like that?