如何在另一个ResourceDictionary中引用_brush_backcolor001? 像这样它不起作用:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:System;assembly=mscorlib">
<ResourceDictionary x:Key="_rd001">
<SolidColorBrush x:Key="_brush_backcolor001">#FF8FBC8F</SolidColorBrush>
</ResourceDictionary>
<Style TargetType="Paragraph" x:Key="_stylePara001">
<Setter Property="TextElement.Background">
<Setter.Value>
<DynamicResource ResourceKey="_brush_backcolor001" />
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
答案 0 :(得分:0)
如果要使用其他资源词典中的资源,可以通过指定ResourceDictionary.MergedDictionaries
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<SolidColorBrush x:Key="_brush_backcolor001">#FF8FBC8F</SolidColorBrush>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="Paragraph" x:Key="_stylePara001">
<Setter Property="TextElement.Background">
<Setter.Value>
<DynamicResource ResourceKey="_brush_backcolor001" />
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
可以提取_brush_backcolor001
以分隔RecourceDictionary
文件,然后通过Source
属性
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="path/to/separate/resouce/file.xaml"/>
</ResourceDictionary.MergedDictionaries>