我有 WPF Application 调用Designer,其中MainWindow(派生自Window)和GraphControl(派生自UserControl)类放置在DesignerAssembly(设置为启动项目)中。应用程序使用了一些其他的程序集,其中的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 Designerassembly 。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未显示在屏幕上,但我只看到一个奇怪的小控件看起来像TextBlockGraphModel.NodeViewModel文本,而不是原始NodeItem控件。它发生在机器人Designer和Package应用程序中。
我的问题是:我做错了什么,我应该如何修复代码以在两个应用程序中进行工作控制。感谢您的关注。