Why is this ColorAnimation not starting?

174 views Asked by At

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.

1

There are 1 answers

0
Julien Lebosquain On BEST ANSWER

Put the VisualStateManager.VisualStateGroups attached property on the root element of your template, the Border in your code. That's where the VisualStateManager is getting its states from.