title: WPF ControlTemplate with VisualStates
body: <p>I want to create a ControlTemplate with predefined VisualStates. I want to use them with GoToStateActions and DataTriggers.</p>
  
  <p>I don't know what exactly is going wrong here. It seems to me, that the Binding isn't established in that way I suppose it is.</p>
  
  <pre><code>namespace ControlTemplateVisualState
  {
      using System.Windows.Controls;
  
  
      public class MyControl : ContentControl
      {
          public MyControl()
          {
              this.DefaultStyleKey = typeof(MyControl);
          }
      }
  }
  </code></pre>
  
      
  
  <pre class="lang-xml prettyprint-override"><code>&lt;ResourceDictionary
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:ControlTemplateVisualState="clr-namespace:ControlTemplateVisualState" 
      xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
      xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"&gt;
  
      &lt;ControlTemplate x:Key="MyControlTemplate" TargetType="{x:Type ControlTemplateVisualState:MyControl}"&gt;
          &lt;Grid x:Name="grid" Background="Red"&gt;
              &lt;VisualStateManager.VisualStateGroups&gt;
                  &lt;VisualStateGroup x:Name="VisualStateGroup"&gt;
                      &lt;VisualState x:Name="IsDisabledState"&gt;
                          &lt;Storyboard&gt;
                              &lt;ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="grid"&gt;
                                  &lt;EasingColorKeyFrame KeyTime="0" Value="#FF2BFF00"/&gt;
                              &lt;/ColorAnimationUsingKeyFrames&gt;
                          &lt;/Storyboard&gt;
                      &lt;/VisualState&gt;
                  &lt;/VisualStateGroup&gt;
              &lt;/VisualStateManager.VisualStateGroups&gt;
              &lt;i:Interaction.Triggers&gt;
                  &lt;ei:DataTrigger Binding="{Binding IsEnabled, ElementName=grid}" Value="False"&gt;
                      &lt;ei:GoToStateAction StateName="IsDisabledState"/&gt;
                  &lt;/ei:DataTrigger&gt;
              &lt;/i:Interaction.Triggers&gt;
          &lt;/Grid&gt;
      &lt;/ControlTemplate&gt;
  
      &lt;Style TargetType="{x:Type ControlTemplateVisualState:MyControl}"&gt;
          &lt;Setter Property="Background" Value="#FF0010FF"/&gt;
          &lt;Setter Property="Template" Value="{StaticResource MyControlTemplate}"/&gt;
      &lt;/Style&gt;
  &lt;/ResourceDictionary&gt;
  
  
  &lt;Window
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      x:Class="ControlTemplateVisualState.MainWindow"
      x:Name="Window"
      xmlns:local="clr-namespace:ControlTemplateVisualState"
      Title="MainWindow"
      Width="640" Height="480"&gt;
  
      &lt;Grid x:Name="LayoutRoot"&gt;
          &lt;local:MyControl IsEnabled="False"/&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>