我的App.xaml中有以下一组代码:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Client.Common;component/Theme/Brushes.xaml"/>
<ResourceDictionary Source="/Client.Common;component/Theme/Fonts.xaml"/>
<ResourceDictionary Source="/Client.Common;component/Theme/CoreStyles.xaml"/>
<ResourceDictionary Source="/Client.Common;component/Theme/SdkStyles.xaml"/>
<ResourceDictionary Source="/Client.Common;component/Theme/MyAppName.xaml"/>
<ResourceDictionary Source="/Client.Common;component/Controls/NavigationPanel.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>NavigationPanel.xaml包含的样式如下所示:
<Style x:Key="NavigationPanelListBox" TargetType="ListBox">
<Setter Property="Background" Value="{StaticResource DarkBackground}" />
<Lots of XAML>
</Style>{StaticResource DarkBackground}在Brushes.xaml文件(即第一个资源字典)中定义。它被定义为
<SolidColorBrush x:Key="DarkBackground" Color="#FF707176" />在资源字典中。
在运行时,我得到以下错误:
Cannot find a Resource with the Name/Key DarkBackground [Line: 16 Position: 44]行号和位置引用app.xaml中的app.xaml资源字典。
我可以引用其他控件的画笔,而不是包含的资源字典。
为什么我不能引用,或者为什么它不解析对合并资源字典中更高级别资源的引用?我在这里错过了什么?
发布于 2012-02-29 07:39:06
您是否在DarkBackground字典中的任何资源中引用NavigationPanel刷子?
如果是,则可能需要将Brushes资源字典合并到NavigationPanel字典中。
所以在NavigationPanel字典里。
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Client.Common;component/Theme/Brushes.xaml" />
</ResourceDictionary.MergedDictionaries>发布于 2012-03-01 05:23:48
您可以将一个字典包含在另一个字典中(如C#中的“使用”),如下所示:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
xmlns:uriMapper="clr-namespace:System.Windows.Navigation;assembly=System.Windows.Controls.Navigation"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:Controls="clr-namespace:APC.IKM.UI.SL.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Brushes.xaml"/>
<ResourceDictionary Source="Fonts.xaml"/>
<ResourceDictionary Source="CoreStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>这就是你要找的吗?Cosmopolitan / Metro项目模板有一个很好的例子.
发布于 2016-06-08 09:07:33
Brushes.xaml和NavigationPanel.xaml是独立解析的,然后添加到合并的应用程序资源字典中,这样他们就不了解彼此了。
https://stackoverflow.com/questions/9494729
复制相似问题