引用VisualState ColorAnimation中的画笔资源

时间:2010-08-02 21:34:41

标签: wpf resources colors visualstatemanager brush

我正在尝试设置Calendar控件的样式,并且需要按钮采用我们已经定义为命名资源的颜色。但是故事板需要ColorAnimation中的颜色,我不知道如何在那里使用画笔。

例如,我需要转一下

<VisualState x:Name="MouseOver">
 <Storyboard>
  <ColorAnimation Duration="00:00:00" Storyboard.TargetName="TextColor" Storyboard.TargetProperty="Color" To="#FF73A9D8"/>
 </Storyboard>

这样的事情:

 <ColorAnimation Duration="00:00:00" Storyboard.TargetName="TextColor" Storyboard.TargetProperty="Color" To="{StaticResource ForegroundBrush}"/>

我该怎么做?

1 个答案:

答案 0 :(得分:1)

我定义了两个资源,Brush依赖于Color

<Color x:Key="ForegroundColor">#whatever</Color>
<SolidColorBrush x:Key="ForegroundBrush" Color="{StaticResource ForegroundColor}"/>

事实上,这与WPF中其他地方使用的技术相同,例如在SystemColors类中。