简体   繁体   English

WPF设计器无法加载Generic.xaml

[英]WPF Designer Failing to Load Generic.xaml

I have written a WPF Class Library. 我已经编写了WPF类库。 It has a Generic.xaml file under a themes folder in the project and also a ThemeInfo attribute in the AssemblyInfo.cs file: 它在项目中的主题文件夹下有一个Generic.xaml文件,在AssemblyInfo.cs文件中还有一个ThemeInfo属性:

[assembly: ThemeInfo(
    ResourceDictionaryLocation.None, 
    ResourceDictionaryLocation.SourceAssembly)]

All works well, except in the designer. 除了在设计器中,其他所有方法都运行良好。 I get blue squigly lines anywhere I am using StaticResource to reference my brushes, styles and other resources saying: 在使用StaticResource引用笔刷,样式和其他资源时,我在任何地方都会看到蓝色的弯曲线条:

The resource '[Resource Name]' cannot be found. 找不到资源“ [资源名称]”。

I really want the designer to pick up my Generic.xaml file and show the controls as I have styled them . 我真的希望设计人员选择我的Generic.xaml文件,并在设置样式时显示控件。 How can I achieve this? 我该如何实现?

UPDATE 更新

I have marked Yogesh's answer as correct but here is some more information. 我已将Yogesh的答案标记为正确,但这是一些更多信息。 I was adding the resource dictionary in the constructor of the App.xaml file, instead of in the xaml. 我在App.xaml文件的构造函数中而不是xaml中添加了资源字典。 The XAML designer does not seem to execute the code behind for the App.xaml file. XAML设计器似乎没有执行App.xaml文件的代码。

Just add a new page named App.xaml with Application as the root element in the class library with Build Action set to Page . 只需添加一个名为App.xaml的新页面,并将Application作为类库中的根元素,并将Build Action设置为Page Now add the generic.xaml file as a resource dictionary. 现在,将generic.xaml文件添加为资源字典。 Something like this... 像这样

<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>

After you do this, rebuild your project, close all xaml views and reopen them again. 完成此操作后,重新生成项目,关闭所有xaml视图,然后再次将其重新打开。 This should fix your issue in VS2012/2013 and Blend 2012. 这应该可以解决VS2012 / 2013和Blend 2012中的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM