【发布时间】:2012-08-14 03:36:27
【问题描述】:
我正在尝试根据控件的状态发生 ColorAnimation。我为 ToggleButton 创建了一个 ControlTemplate,看起来像这样:
<ControlTemplate TargetType="ToggleButton">
<Border>
<Grid>
<VisualStateManager.VisualStateGroup>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimation Storyboard.TargetName="ColorChangeRect"
Storyboard.TargetProperty="(Rectangle.Fill).(SolidColorBrush.Color)"
To="Blue" Duration="0:0:3" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroup>
<Rectangle x:Name=ColorChangeRect" Fill="Red" />
<ContentPresenter Content="{TemplateBinding Content}" />
</Grid>
</Border>
</ControlTemplate>
不幸的是,什么都没有发生。我不确定我在这里缺少什么。
【问题讨论】:
-
哇哇 D:我现在清楚地看到了我的问题。我应该在我的办公桌上放一只橡皮鸭。 @_@
标签: wpf controltemplate togglebutton visualstatemanager coloranimation