![](/img/trans.png)
[英]WPF Custom Control- Generic.xaml root element not supported by visual designer
[英]WPF Designer Failing to Load Generic.xaml
我已经编写了WPF类库。 它在项目中的主题文件夹下有一个Generic.xaml文件,在AssemblyInfo.cs文件中还有一个ThemeInfo属性:
[assembly: ThemeInfo(
ResourceDictionaryLocation.None,
ResourceDictionaryLocation.SourceAssembly)]
除了在设计器中,其他所有方法都运行良好。 在使用StaticResource引用笔刷,样式和其他资源时,我在任何地方都会看到蓝色的弯曲线条:
找不到资源“ [资源名称]”。
我真的希望设计人员选择我的Generic.xaml文件,并在设置样式时显示控件。 我该如何实现?
更新
我已将Yogesh的答案标记为正确,但这是一些更多信息。 我在App.xaml文件的构造函数中而不是xaml中添加了资源字典。 XAML设计器似乎没有执行App.xaml文件的代码。
只需添加一个名为App.xaml
的新页面,并将Application
作为类库中的根元素,并将Build Action
设置为Page
。 现在,将generic.xaml文件添加为资源字典。 像这样
<Application x:Class="[YourNamespace].App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="[AbsoluteOrRelativePath]/Generic.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
完成此操作后,重新生成项目,关闭所有xaml视图,然后再次将其重新打开。 这应该可以解决VS2012 / 2013和Blend 2012中的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.