1
votes

im a little bit stuck with my current project and hope someone can help me out of this.

My application works with plugins so that the user is able to add additional functionality to the application. Now i would like to have the configuration window in the same style (Maybe a plugin need some kind of configurations).

The configuration window loads all plugins and get the configuration ViewModel from the plugins. All the ViewModels are stored in an ObservableCollection. These ViewModels should be displayed in a TabControl (one tab per ViewModel)

But i dont know the type of UserControl the plugin is using, because the plugin come up with its own UserControl for configuration purposes. Otherwise i would create a TabControl, bind its ItemsSource to the ObservableCollection and specify the UserControl in the Resources (DataTemplates).

But how to do it in case the UserControls are unknown to compile time?

I thought about using a ObservableCollection instead of ViewModels, but im not realy happy with that and even dont know if this will work.

Do you have some idea how to deal with that?

Kind regards,

SyLuS

1
plugin should have some common interfaceLei Yang
hi, in case of plugin, you must retrieve "IUserControl" element (that internally can create is own viewmodel and so on) - it is not the role of the app to template the viewmodel of the plugin. So you can't bind your tabsGCamel
@Lei Yang: Ive wrote a common interface to ensure functions like "SaveConfiguration", "LoadConfiguration", "ResetToDefault", ... Thats not the problem.SyLuS
@GCamel: Thats what im doing, a "Plugin" must have a method "GetConfigurationViewModel" which will be used to initialize and return the ViewModel of the Configuration. I could also ensure a method "GetConfigurationView" to get the UserControl from the Plugin. But whats the best way to bind the ViewModel and the View/ViewModel into my configuration windowl?SyLuS
You can't. The normal way would be to bind the viewmodel collection to the tab control, but you don't own the plugin datatemplate definition for the view...so you must call GetConfigurationView and put the view in the tab - no MVVM pattern in this case. or you have to find a way to include the dict xaml from your plugin in your app (based on naming) so that the tab can resolve the template ?GCamel

1 Answers

1
votes

You could use a ContentControl to achieve this.

It's used to show views depending on their viewmodel. In your xaml you can specifiy which view should be shown. Based on the viewmodel which is the current DataContext.

<ContentControl>
    <ContentControl.Resources>
        <DataTemplate DataType="{x:Type vm:MyViewModel}">
            <v:MyView/>
        </DataTemplate>
    </<ContentControl.Resources>
</ContentControl>

But when you say you are using a plugin system, maybe something like PRISM, you have to setup the datatemplates automatically. Never done this before. But maybe I gave you a point where you can start.