![](/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.