WPF-资源未从Generic.xaml加载 [英] WPF - Resource not loading from Generic.xaml
问题描述
主题\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>
Controls\Layout\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>
如果我将整个样式复制到我的usercontrol资源中,则可以正常工作。但是,如果我不这样做,则用户控件显示为空。在Expression Blend 4中,我右键单击并选择编辑模板
>,但是它不允许我选择编辑副本...
,这使我相信有些严重错误并且Generic.xaml无法正确加载。我认为它是Generic.xaml,因为如果我删除MergedDictionary调用并将xaml样式直接复制/粘贴到Generic.xaml中,它仍然无法使用。
If I copy the entire style into my usercontrol resources it works fine. But, if I don't, the usercontrol shows up empty. In Expression Blend 4, I right-clicked and chose Edit Template
>, but it won't let me select Edit a Copy...
which leads me to believe that something is severely wrong and the Generic.xaml isn't loading properly. I figure it's Generic.xaml because if I remove the MergedDictionary call and copy/paste the xaml style directly into Generic.xaml it still doesn't work.
推荐答案
我会做出一个疯狂的猜测,即您更改了AssemblyInfo.cs文件并更改了(或删除了)以下行:
I'm gonna take a wild guess that you altered your AssemblyInfo.cs file and either changed (or removed) the following line:
[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。 :)
You need to tell your assembly about your ThemeInfo. :)
这篇关于WPF-资源未从Generic.xaml加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!