【发布时间】:2012-09-08 05:23:42
【问题描述】:
我正在创建单选按钮样式。 RadioButton 有一个承载 ContentControl 的边框。 ContentControl 将其 Content 属性设置为在单独的 ResourceDictionary 中声明的 Path (FemaleVector)。当单选按钮 IsChecked 时,如何更改路径的 Fill 属性?以下是我到目前为止所拥有的。我可以更改边框的背景属性,但设置 ContentControl 的 Foreground 属性不会更改路径的颜色。 (没想到会这样。)
<Style x:Key="Female" TargetType="{x:Type RadioButton}">
<Setter Property="Margin" Value="0,0,5,0"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RadioButton}">
<Border x:Name="border" Padding="7,3,7,3" Width="35" Height="35" BorderBrush="#8CD567DC" Background="#00D567DC" CornerRadius="5" BorderThickness="0.8">
<ContentControl x:Name="content" Content="{DynamicResource FemaleVector}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Background" TargetName="border" Value="#8CD567DC"/>
<Setter Property="Foreground" TargetName="content" Value="Blue"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我不喜欢在我的样式中包含路径的长 Data 属性,因此我将它们移到了单独的 ResourceDictionary 中。我应该将路径放回我的样式中,而不是将其保存在单独的 ResourceDictionary 中吗?
【问题讨论】: