I'm trying to style the Calendar control and need 开发者_StackOverflow中文版the buttons to adopt the colors we already have defined as named resources. But the storyboards require colors in the ColorAnimation, and I'm not sure how to use a brush there.
For example, I need to turn this
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimation Duration="00:00:00" Storyboard.TargetName="TextColor" Storyboard.TargetProperty="Color" To="#FF73A9D8"/>
</Storyboard>
Into something like this:
<ColorAnimation Duration="00:00:00" Storyboard.TargetName="TextColor" Storyboard.TargetProperty="Color" To="{StaticResource ForegroundBrush}"/>
How do I do this?
I define two resources, the Brush
dependent on the Color
:
<Color x:Key="ForegroundColor">#whatever</Color>
<SolidColorBrush x:Key="ForegroundBrush" Color="{StaticResource ForegroundColor}"/>
This is, in fact, the same technique used elsewhere in WPF, such as in the SystemColors
class.
精彩评论