title: WPF: how to fire an EventTrigger (or Animation) when binding changes?
body: <p>We have a simple animation that runs when a ToggleButton is checked and unchecked (expands a ListView's height and then collapses a ListView's height).  How do you fire the EventTrigger (or Animation) for the <code>&lt;Storyboard x:Key="CommentsCollapse"&gt;</code> when the DataContext Binding changes in the <code>x:Name="DetailsGrid"</code> Grid in the following XAML?</p>
  
  <p>In other words, whenever the Binding changes for the "DetailsGrid", we want the "CommentsCollapse" StoryBoard to be triggered to ensure the ListView is returned to its collapsed state.</p>
  
  <pre><code>&lt;Page
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     Width="800"
     Height="400"&gt;
     &lt;Page.Resources&gt;
        &lt;Storyboard x:Key="CommentsExpand"&gt;
           &lt;DoubleAnimationUsingKeyFrames
              BeginTime="00:00:00"
              Storyboard.TargetName="CommentsListView"
              Storyboard.TargetProperty="(FrameworkElement.Height)"&gt;
              &lt;SplineDoubleKeyFrame KeyTime="00:00:00.200" Value="300"/&gt;
           &lt;/DoubleAnimationUsingKeyFrames&gt;
        &lt;/Storyboard&gt;
        &lt;Storyboard x:Key="CommentsCollapse"&gt;
           &lt;DoubleAnimationUsingKeyFrames
              BeginTime="00:00:00"
              Storyboard.TargetName="CommentsListView"
              Storyboard.TargetProperty="(FrameworkElement.Height)"&gt;
              &lt;SplineDoubleKeyFrame KeyTime="00:00:00.200" Value="75"/&gt;
           &lt;/DoubleAnimationUsingKeyFrames&gt;
        &lt;/Storyboard&gt;
     &lt;/Page.Resources&gt;
     &lt;Page.Triggers&gt;
        &lt;EventTrigger RoutedEvent="ToggleButton.Checked" SourceName="CommentsToggleButton"&gt;
           &lt;BeginStoryboard Storyboard="{StaticResource CommentsExpand}"/&gt;
        &lt;/EventTrigger&gt;
        &lt;EventTrigger RoutedEvent="ToggleButton.Unchecked" SourceName="CommentsToggleButton"&gt;
           &lt;BeginStoryboard Storyboard="{StaticResource CommentsCollapse}"/&gt;
        &lt;/EventTrigger&gt;
     &lt;/Page.Triggers&gt;
     &lt;Grid DataContext="{Binding Path=CurrentTask.Workflow.Invoice}" x:Name="DetailsGrid"&gt;
        &lt;StackPanel Orientation="Horizontal"&gt;
           &lt;Canvas Width="428"&gt;
              &lt;GroupBox Width="422" Margin="5,0,0,0"&gt;
                 &lt;GroupBox.Header&gt;
                    &lt;StackPanel Orientation="Horizontal"&gt;
                       &lt;ToggleButton
                          x:Name="CommentsToggleButton"
                          Width="20"
                          Height="10"
                          Margin="5,0,0,0"&gt;
                          &lt;ToggleButton.Content&gt;
                             &lt;Rectangle
                                Width="5"
                                Height="5"
                                Fill="Red"/&gt;
                          &lt;/ToggleButton.Content&gt;
                       &lt;/ToggleButton&gt;
                       &lt;TextBlock Foreground="Blue" Text="Comments"/&gt;
                    &lt;/StackPanel&gt;
                 &lt;/GroupBox.Header&gt;
                 &lt;ListView
                    x:Name="CommentsListView"
                    Height="75"
                    ItemsSource="{Binding Path=Comments}"&gt;
                    &lt;ListView.View&gt;
                       &lt;GridView&gt;
                          &lt;GridViewColumn DisplayMemberBinding="{Binding Path=Date}" Header="Date"/&gt;
                          &lt;GridViewColumn DisplayMemberBinding="{Binding Path=Name}" Header="User"/&gt;
                          &lt;GridViewColumn DisplayMemberBinding="{Binding Path=Description}" Header="Comment"/&gt;
                       &lt;/GridView&gt;
                    &lt;/ListView.View&gt;
                 &lt;/ListView&gt;
              &lt;/GroupBox&gt;
           &lt;/Canvas&gt;
        &lt;/StackPanel&gt;
     &lt;/Grid&gt;
  &lt;/Page&gt;
  </code></pre>