我有 WPF Application 调用Designer
,其中MainWindow
(派生自Window
)和GraphControl
(派生自UserControl
)类放置在Designer
Assembly(设置为启动项目)中。应用程序使用了一些其他的程序集,其中的GraphModel
程序集包含使用的控件的视图模型。
我在 中几乎没有DataTemplate
声明GraphControl.xaml
,即(简化列表):
<UserControl x:Class="Designer.GraphControl"
xmlns:GraphModel="clr-namespace:GraphModel;assembly=GraphModel">
<UserControl.Resources>
<ResourceDictionary>
<DataTemplate DataType="{x:Type GraphModel:NodeViewModel}">
<!-- (...) -->
</DataTemplate>
</ResourceDictionary>
</UserControl.Resources>
</UserControl>
应用程序Designer
正常工作,因为它被发明了。之后,我创建了新Visual Studio Package
项目,为 VS2012 制作自定义编辑器,我需要在项目中使用我GraphControl
的 from Designer
assembly 。Package
我注意到我在Package
项目中合并 WPF 控件的尝试导致异常:
System.Windows.Markup.XamlParseException
Message=Set property 'System.Windows.ResourceDictionary.DeferrableContent' threw an exception.
Source=PresentationFramework
LineNumber=0
LinePosition=0
InnerException: System.IO.FileNotFoundException
Source=mscorlib
Message=Could not load file or assembly 'GraphModel, PublicKeyToken=c2639211081ade27' or one of its dependencies. The system cannot find the file specified.
此后,我发现如果我x:key
向上述元素添加属性,DataTemplate
则不会引发上述异常并且控件显示在Designer
应用程序和Package
应用程序中,但由 表示的 UI 元素(NodeItem
控件)NodeViewModel
未显示在屏幕上,但我只看到一个奇怪的小控件看起来像TextBlock
GraphModel.NodeViewModel文本,而不是原始NodeItem
控件。它发生在机器人Designer
和Package
应用程序中。
我的问题是:我做错了什么,我应该如何修复代码以在两个应用程序中进行工作控制。感谢您的关注。