1
我使用AvalonDock和MEF插件架构, 每个插件都返回一个数据模板主机,主机获取数据模板,插入到主数据模板。如何将多个数据模板插入到主日期模板
以下是在被转换成的DataTemplates
用户控件MainMethodView:包括选项卡,
PluginA的MethodView:需要被插入到MainMethodView的标签项1.
PluginB的MethodView:需要被插入到MainMethodView的标签条目2中。
.....
谢谢。
代码:InitializePlugins()我只有能显示一个插件的DataTemplate中。和GetMethodViewTemplate()给我错误:ContentControl的内容必须是单个元素。
参考:Link1
public void InitializePlugins(){
var templateSelector = new PanesTemplateSelector();
templateSelector.MethodViewTemplate = pluginService.Plugins[0].MethodViewTemplate;
_dockingManger.LayoutItemTemplateSelector = templateSelector;
}
private static DataTemplate GetMethodViewTemplate(PluginService pluginService) {
FrameworkElementFactory factory = new FrameworkElementFactory(typeof(MethodView));
foreach (var plugin in pluginService.Plugins) {
FrameworkElementFactory fef = new FrameworkElementFactory(typeof(ContentControl));
fef.SetValue(ContentControl.ContentTemplateProperty, plugin.MethodViewTemplate);
factory.AppendChild(fef);
}
DataTemplate dt = new DataTemplate();
dt.VisualTree = factory;
return dt;
}
的另一个问题是数据绑定,MainMethodViewModel具有插件,如何将其绑定到MainMethodView PluginMethodViewModels。