I encountered an issue with a ControlTemplate
for ToggleButton
I created.
When the button is Checked
, a ColorAnimation
is triggered and the control's background changes color. However, if the user enters the MouseOver
state, another animation is triggered that affects the button's background as well.
When the mouse is no longer in the MouseOver
state, the control does not return to the color it should be while it is in the Checked
state. I'm not sure why this does not persist when the MouseOver
state is triggered.
The VisualStateManager
portion of my ControlTemplate
looks sorta like this:
<VisualStateManger.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"></VisualState>
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimation Storyboard.TargetName="BackgroundBorder"
Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
To="Gold" Duration="0:0:0.3" />
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="CheckedStates">
<VisualState x:Name="Checked">
<Storyboard>
<ColorAnimation Storyboard.TargetName="BackgroundBorder"
Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
To="PaleGoldenrod" Duration="0:0:0.3" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>