如何在另一个_brush_backcolor001中引用ResourceDictionary?就像这样没用的:
<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>发布于 2014-06-18 11:42:12
如果您想使用其他资源字典中的资源,可以通过指定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>https://stackoverflow.com/questions/24284446
复制相似问题