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