xaml - ResourceDictionary 找不到另一个 ResourceDictionary
问题描述
我将为一些控件创建一个简单的主题。我现在的问题是从第一个 ResourceDictionary 访问到第二个 ResourceDictionary。
示例: ResourceDictionary1 ( DicColors ) 包含颜色,第二个 ResourceDictionary ( DicThemeColor ) 需要来自DicColors的颜色来构建 SolidColorBrush:
迪克色
<Color x:Key="Color_System_Green">##8ec760</Color>
<Color x:Key="Color_System_Blue">#53baf2</Color>
<Color x:Key="Color_System_Orange">#ff9a1e</Color>
Dic主题颜色
<SolidColorBrush x:Key="Button.Static.Background" Color="{StaticResource Color_System_Green}"/>
<SolidColorBrush x:Key="Button.MouseOver.Background Color="{StaticResource Color_System_Blue}"/>
<SolidColorBrush x:Key="Button.Pressed.Background" Color="{StaticResource Color_System_Orange}"/>
目标是,在单个 ResourceDictionary 中定义颜色,其他 ResourceDictionaries 可以从中使用此颜色。我现在的问题是,我无法从DicThemeColor访问DicColors
示例:我将更改背景。这里是按钮默认模板的片段。在 App.xaml 中,我合并了 ResourceDictionaries。
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/TestApp;component/Styles/Colors/DicColors.xaml" />
<ResourceDictionary Source="pack://application:,,,/TestApp;component/Styles/Controls/DicThemeColor.xaml" />
</ResourceDictionary.MergedDictionaries>
现在这里是按钮的默认模板。我只改变了背景。您可以在此处看到最后一行的更改。
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestApp.Styles.Controls">
<Style x:Key="FocusVisual">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<SolidColorBrush x:Key="Button.Static.Background" Color="{DynamicResource Color.Button.Static.Background}"/>
当我将这种样式用于按钮时,我得到的是白色背景而不是绿色。我不知道为什么。
希望您能够帮助我。
问候
解决方案
我认为您需要更改对两个资源字典的引用以阅读:
<ResourceDictionary Source="pack://application:,,,/Styles/Colors/DicColors.xaml" />
<ResourceDictionary Source="pack://application:,,,/Styles/Controls/DicThemeColor.xaml" />
不知道您的文件夹结构,您可能需要稍微调整一下。
推荐阅读
- python - OPENERP 6.1 中函数 GROUP_BY 中的字段翻译
- android - 错误快速框登录
- r - 朴素贝叶斯错误:下标越界
- r - R中的圆形或/功能错误?
- powershell - 基于注释的帮助的正确语法 .EXAMPLE
- c# - 异常没有给出它发生的文件或行
- javascript - FullCalendar 行 Javascript
- c# - 我应该使用什么模式来防止耗时过长的异步调用溢出
- java - Android:访问内部 AsyncTask 类的变量,但在片段的 onCreateView 中将其设置为 null
- git - git rebase/checkout 保留最新修改的文件