Question

I am trying to develop a MEF plugin software, use notepad++ as an example, each tab will show a view that imported from each plugin.

the following interface would provide one instance of ConfigView after MEF composition. but how to create multiple instances of ConfigView?

public interface IPluginA:IPlugin {
    // View, user control
    FrameworkElement CongfigView { get; }
}

--------Possible Solution--------------------------------------------------------------------

Actually, I am trying to use it in AvalonDock, and found avalonDock needs dataTemplate to create multiple views. In this way, plugins only need to provide one view data template.

internal class PanesTemplateSelector : DataTemplateSelector {


    private DataTemplate _fileViewTemplate;
    public DataTemplate FileViewTemplate {
        get {
            return _fileViewTemplate;
        }
        set { _fileViewTemplate = value; }
    }

    public DataTemplate FileStatsViewTemplate {
        get;
        set;
    }


    public PanesTemplateSelector() {
        // convert from usercontrol to data template
        FrameworkElementFactory factory = new FrameworkElementFactory(typeof(FileView));
        DataTemplate dt = new DataTemplate();
        dt.VisualTree = factory;

        _fileViewTemplate = dt;
    }

    public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container) {

        var itemAsLayoutContent = item as LayoutContent;

        if (item is FileViewModel)
            return FileViewTemplate;

        if (item is FileStatsViewModel)
            return FileStatsViewTemplate;

        return base.SelectTemplate(item, container);
    }
}

Thanks

Was it helpful?

Solution

Just keep multiple views, instead of one... You can keep List or FrameworkElement[] based on if you want to create new ones dynamically or not

public interface IPluginA:IPlugin {
    // View, user control
    IList<FrameworkElement> CongfigViews { get; }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top