16

主题\Generic.xaml:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="WPF Commons;component/Controls/Layout/Foo/FooItem.xaml" />
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

控件\布局\Foo\FooItem.xaml:

<Style TargetType="{x:Type l:FooItem}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type l:FooItem}">
                <Border>
                    <ContentPresenter ContentSource="Header" />
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>


如果我将整个样式复制到我的用户控件资源中,它可以正常工作。但是,如果我不这样做,用户控件就会显示为空。在 Expression Blend 4 中,我右键单击并选择了Edit Template>,但它不允许我选择Edit a Copy...,这使我相信某些事情严重错误并且 Generic.xaml 没有正确加载。我认为它是 Generic.xaml,因为如果我删除 MergedDictionary 调用并将 xaml 样式直接复制/粘贴到 Generic.xaml 中,它仍然不起作用。

4

2 回答 2

31

我会大胆猜测您更改了 AssemblyInfo.cs 文件并更改(或删除)以下行:

[assembly: ThemeInfo(
    ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
    //(used if a resource is not found in the page, 
    // or application resource dictionaries)
    ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
    //(used if a resource is not found in the page, 
    // app, or any theme specific resource dictionaries)
)]

您需要告诉您的程序集您的 ThemeInfo。:)

于 2011-04-12T17:23:06.600 回答
1

从我的博客复制:http: //zoomicon.wordpress.com/2012/06/10/what-to-do-if-generic-xaml-doesnt-get-loaded-for-wpf-control/

在您需要的 Properties\AssemblyInfo.cs 的开头(注意这在 Silverlight 中不使用/不需要):使用 System.Windows;

...

请注意,如果项目在解决方案资源管理器中没有显示属性节点,您必须使用正确的模板(对于 WPF 自定义控件)创建一个新项目,或者右键单击该项目,选择属性,然后按程序集信息按钮并输入一些虚拟值,然后确定以创建属性节点(这也创建到属性子文件夹和 AssemblyInfo.cs 文件)。

您可以在解决方案资源管理器中展开(下拉)特殊属性节点,然后打开 AssemblyInfo.cs 并添加上述内容(如果缺少)

于 2012-06-10T14:30:34.563 回答