title: Visual State Manager in WPF not working for me
body: <p>In a wpf project I have this XAML code </p>
  
  <pre><code>&lt;Window
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  mc:Ignorable="d" 
  xmlns:ic="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
  x:Class="WpfApplication1.MainWindow"
  xmlns:vsm="clr-namespace:System.Windows;assembly=WPFToolkit"
  x:Name="Window"
  Title="MainWindow"
  Width="640" Height="480"&gt;
  &lt;vsm:VisualStateManager.VisualStateGroups&gt;
      &lt;vsm:VisualStateGroup x:Name="VisualStateGroup"&gt;
          &lt;vsm:VisualState x:Name="Loading"&gt;
              &lt;Storyboard&gt;
                  &lt;ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="control" Storyboard.TargetProperty="(UIElement.Visibility)"&gt;
                      &lt;DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Visible}"/&gt;
                  &lt;/ObjectAnimationUsingKeyFrames&gt;
                  &lt;ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="button" Storyboard.TargetProperty="(UIElement.Visibility)"&gt;
                      &lt;DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Collapsed}"/&gt;
                  &lt;/ObjectAnimationUsingKeyFrames&gt;
                  &lt;ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="button1" Storyboard.TargetProperty="(UIElement.Visibility)"&gt;
                      &lt;DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Visible}"/&gt;
                  &lt;/ObjectAnimationUsingKeyFrames&gt;
              &lt;/Storyboard&gt;
          &lt;/vsm:VisualState&gt;
          &lt;VisualState x:Name="Normal"&gt;
              &lt;Storyboard&gt;
                  &lt;ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="control" Storyboard.TargetProperty="(UIElement.Visibility)"&gt;
                      &lt;DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Collapsed}"/&gt;
                  &lt;/ObjectAnimationUsingKeyFrames&gt;
              &lt;/Storyboard&gt;
          &lt;/VisualState&gt;
      &lt;/vsm:VisualStateGroup&gt;
  &lt;/vsm:VisualStateManager.VisualStateGroups&gt;
  &lt;Grid x:Name="LayoutRoot"&gt;
      &lt;Grid.Resources&gt;
          &lt;ControlTemplate x:Key="loadingAnimation"&gt;
              &lt;Image x:Name="content" Opacity="1"&gt;
                  &lt;Image.Source&gt;
                      &lt;DrawingImage&gt;
                          &lt;DrawingImage.Drawing&gt;
                              &lt;DrawingGroup&gt;
                                  &lt;GeometryDrawing Brush="Transparent"&gt;
                                      &lt;GeometryDrawing.Geometry&gt;
                                          &lt;RectangleGeometry Rect="0,0,1,1"/&gt;
                                      &lt;/GeometryDrawing.Geometry&gt;
                                  &lt;/GeometryDrawing&gt;
                                  &lt;DrawingGroup&gt;
                                      &lt;DrawingGroup.Transform&gt;
                                          &lt;RotateTransform x:Name="angle" Angle="0" CenterX="0.5" CenterY="0.5"/&gt;
                                      &lt;/DrawingGroup.Transform&gt;
                                      &lt;GeometryDrawing Geometry="M0.9,0.5 A0.4,0.4,90,1,1,0.5,0.1"&gt;
                                          &lt;GeometryDrawing.Pen&gt;
                                              &lt;Pen Brush="Green" Thickness="0.1"/&gt;
                                          &lt;/GeometryDrawing.Pen&gt;
                                      &lt;/GeometryDrawing&gt;
                                      &lt;GeometryDrawing Brush="Green" Geometry="M0.5,0 L0.7,0.1 L0.5,0.2"/&gt;
                                  &lt;/DrawingGroup&gt;
                              &lt;/DrawingGroup&gt;
                          &lt;/DrawingImage.Drawing&gt;
                      &lt;/DrawingImage&gt;
                  &lt;/Image.Source&gt;
              &lt;/Image&gt;
              &lt;ControlTemplate.Triggers&gt;
                  &lt;Trigger Property="Visibility" Value="Visible"&gt;
                      &lt;Trigger.EnterActions&gt;
                          &lt;BeginStoryboard x:Name="animation"&gt;
                              &lt;Storyboard&gt;
                                  &lt;DoubleAnimation From="0" To="359" Duration="0:0:1.5" RepeatBehavior="Forever"
                                      Storyboard.TargetName="angle" Storyboard.TargetProperty="Angle"/&gt;
                              &lt;/Storyboard&gt;
                          &lt;/BeginStoryboard&gt;
                      &lt;/Trigger.EnterActions&gt;
                      &lt;Trigger.ExitActions&gt;
                          &lt;StopStoryboard BeginStoryboardName="animation"/&gt;
                      &lt;/Trigger.ExitActions&gt;
                  &lt;/Trigger&gt;
              &lt;/ControlTemplate.Triggers&gt;
          &lt;/ControlTemplate&gt;
      &lt;/Grid.Resources&gt;
      &lt;Grid.ColumnDefinitions&gt;
          &lt;ColumnDefinition MinWidth="76.128" Width="Auto"/&gt;
          &lt;ColumnDefinition MinWidth="547.872" Width="Auto"/&gt;
      &lt;/Grid.ColumnDefinitions&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition Height="0.05*"/&gt;
          &lt;RowDefinition Height="0.95*"/&gt;
      &lt;/Grid.RowDefinitions&gt;
      &lt;Button x:Name="button" Margin="0,0,1,0.04" Width="100" Content="Load" d:LayoutOverrides="Height" Click="Button1_Click"/&gt;
      &lt;Button x:Name="button1" HorizontalAlignment="Left" Margin="0,0,0,0.04" Width="100" Content="Stop" Grid.Column="1" d:LayoutOverrides="Height" Click="Button2_Click" Visibility="Collapsed"/&gt;
      &lt;Control x:Name="control" Margin="10" Height="100" Grid.Row="1" Grid.ColumnSpan="2" Width="100" Template="{DynamicResource loadingAnimation}" Visibility="Collapsed"/&gt;
  &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>and the following code behind on the window</p>
  
  <pre><code>public partial class MainWindow : Window
      {
          public MainWindow()
          {
              this.InitializeComponent();
  
          }
  
  
          private void Button1_Click(object sender, System.Windows.RoutedEventArgs e)
          {
                  VisualStateManager.GoToState(this, "Loading", true);
          }
  
          private void Button2_Click(object sender, System.Windows.RoutedEventArgs e)
          {
              VisualStateManager.GoToState(this, "Normal", true);
          }
      }
  </code></pre>
  
  <p>However, when I click the first button (button1) the state change is not being triggered.
  What am I doing wrong?</p>
  
  <p>Thanks in advance</p>