I'm trying to get a ColorAnimation to occur depending on the control's state. I created a ControlTemplate for the ToggleButton that looks something like this:
<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>
Unfortunately, nothing is occuring. I'm not sure what I'm missing here.
Put the
VisualStateManager.VisualStateGroupsattached property on the root element of your template, theBorderin your code. That's where theVisualStateManageris getting its states from.