title: TargetName property cannot be set on a Style Setter, so how is it set?
body: <p>I've spent this past week exploring WPF so it's still very new to me.  One of the things I'm working on is simple animations.  In this case a bouncing smiley face.</p>
  
  <p>My plan of attack is:</p>
  
  <ol>
  <li>Make a smiley face.  I've done this.</li>
  <li>Work out the bouncing animation on a simple object.  I've done this.</li>
  <li>Abstract that animation so it can be used in several places (the elements of the smiley face).  I'm stuck here.</li>
  <li>Apply the abstracted animation style to all the elements of the smiley face.</li>
  </ol>
  
  <p>After step #2 I had the the following working XAML:</p>
  
  <pre><code>&lt;Window x:Class="MainWindow"
          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"
          xmlns:local="clr-namespace:WpfApplication1"
          mc:Ignorable="d"
          Title="Test Window" Height="350" Width="620"&gt;
      &lt;Grid&gt;
          &lt;Canvas Margin="0,180,0,0"&gt;
              &lt;Ellipse Canvas.Left="10" Canvas.Top="10" Width="100" Height="100" Stroke="Blue" StrokeThickness="4" Fill="Aqua" /&gt;
              &lt;Ellipse Canvas.Left="30" Canvas.Top="12" Width="60" Height="30"&gt;
                  &lt;Ellipse.Fill&gt;
                      &lt;LinearGradientBrush StartPoint="0.45,0" EndPoint="0.5, 0.9"&gt;
                          &lt;GradientStop Offset="0.2" Color="DarkMagenta" /&gt;
                          &lt;GradientStop Offset="0.7" Color="Transparent" /&gt;
                      &lt;/LinearGradientBrush&gt;
                  &lt;/Ellipse.Fill&gt;
              &lt;/Ellipse&gt;
              &lt;Ellipse Canvas.Left="33" Canvas.Top="35" Width="20" Height="20" Stroke="Blue" StrokeThickness="3" Fill="White" /&gt;
              &lt;Ellipse Canvas.Left="40" Canvas.Top="43" Width="6" Height="5" Fill="Black" /&gt;
              &lt;Ellipse Canvas.Left="68" Canvas.Top="35" Width="20" Height="20" Stroke="Blue" StrokeThickness="3" Fill="White" /&gt;
              &lt;Ellipse Canvas.Left="75" Canvas.Top="43" Width="6" Height="5" Fill="Black" /&gt;
              &lt;Path Name="mouth" Stroke="Blue" StrokeThickness="4" Data="M 35,75 Q 55,90 80,75 " /&gt;
          &lt;/Canvas&gt;
          &lt;Grid Margin="100,5,0,0" Width="75" Height="300"&gt;
              &lt;Canvas&gt;
                  &lt;Ellipse Height="40" Width="40" x:Name="theBall" Canvas.Left="16"&gt;
                      &lt;Ellipse.Fill&gt;
                          &lt;RadialGradientBrush GradientOrigin="0.75,0.25"&gt;
                              &lt;GradientStop Color="Yellow" Offset="0.0" /&gt;
                              &lt;GradientStop Color="Red" Offset="1.0" /&gt;
                          &lt;/RadialGradientBrush&gt;
                      &lt;/Ellipse.Fill&gt;
                      &lt;Ellipse.RenderTransform&gt;
                          &lt;TransformGroup&gt;
                              &lt;ScaleTransform x:Name="aniSquash"/&gt;
                              &lt;TranslateTransform x:Name="aniBounce"/&gt;
                          &lt;/TransformGroup&gt;
                      &lt;/Ellipse.RenderTransform&gt;
                      &lt;Ellipse.Triggers&gt;
                          &lt;EventTrigger RoutedEvent="Loaded"&gt;
                              &lt;BeginStoryboard&gt;
                                  &lt;Storyboard SpeedRatio="2.0"&gt;
                                      &lt;DoubleAnimationUsingKeyFrames Duration="0:0:4.5" Storyboard.TargetName="aniBounce" Storyboard.TargetProperty="Y" RepeatBehavior="Forever"&gt;
                                          &lt;LinearDoubleKeyFrame Value="120" KeyTime="0:0:0"/&gt;
                                          &lt;SplineDoubleKeyFrame Value="260" KeyTime="0:0:2.2" KeySpline="0, 0, 0.5, 0"/&gt;
                                          &lt;LinearDoubleKeyFrame Value="260" KeyTime="0:0:2.25"/&gt;
                                          &lt;SplineDoubleKeyFrame Value="120" KeyTime="0:0:4.5" KeySpline="0, 0, 0, 0.5"/&gt;
                                      &lt;/DoubleAnimationUsingKeyFrames&gt;
                                      &lt;DoubleAnimationUsingKeyFrames Duration="0:0:4.5" Storyboard.TargetName="aniSquash" Storyboard.TargetProperty="ScaleX" RepeatBehavior="Forever"&gt;
                                          &lt;LinearDoubleKeyFrame Value="1" KeyTime="0:0:0"/&gt;
                                          &lt;LinearDoubleKeyFrame Value="1" KeyTime="0:0:2"/&gt;
                                          &lt;LinearDoubleKeyFrame Value="1.3" KeyTime="0:0:2.25"/&gt;
                                          &lt;LinearDoubleKeyFrame Value="1" KeyTime="0:0:2.5"/&gt;
                                      &lt;/DoubleAnimationUsingKeyFrames&gt;
                                      &lt;DoubleAnimationUsingKeyFrames Duration="0:0:4.5" Storyboard.TargetName="aniSquash" Storyboard.TargetProperty="ScaleY" RepeatBehavior="Forever"&gt;
                                          &lt;LinearDoubleKeyFrame Value="1" KeyTime="0:0:0"/&gt;
                                          &lt;LinearDoubleKeyFrame Value="1" KeyTime="0:0:2"/&gt;
                                          &lt;LinearDoubleKeyFrame Value="0.7" KeyTime="0:0:2.25"/&gt;
                                          &lt;LinearDoubleKeyFrame Value="1" KeyTime="0:0:2.5"/&gt;
                                      &lt;/DoubleAnimationUsingKeyFrames&gt;
                                  &lt;/Storyboard&gt;
                              &lt;/BeginStoryboard&gt;
                          &lt;/EventTrigger&gt;
                      &lt;/Ellipse.Triggers&gt;
                  &lt;/Ellipse&gt;
                  &lt;Rectangle Height="5" Canvas.Left="10" Canvas.Top="285" Width="55" Fill="Black"/&gt;
              &lt;/Canvas&gt;
          &lt;/Grid&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>While altering the above, working, XAML for step #3 I introduced an error I don't really understand.  Here is the altered XAML that doesn't work:</p>
  
  <pre><code>&lt;Window x:Class="MainWindow"
          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"
          xmlns:local="clr-namespace:WpfApplication1"
          mc:Ignorable="d"
          Title="Test Window" Height="350" Width="620"&gt;
      &lt;Window.Resources&gt;
          &lt;TransformGroup x:Key="aniBounceAndSquash"&gt;
              &lt;ScaleTransform x:Name="aniSquash"/&gt;
              &lt;TranslateTransform x:Name="aniBounce"/&gt;
          &lt;/TransformGroup&gt;
          &lt;Style x:Key="styleBounceAndSquash" TargetType="FrameworkElement"&gt;
              &lt;Setter Property="RenderTransform" Value="{StaticResource aniBounceAndSquash}" /&gt;
              &lt;Style.Triggers&gt;
                  &lt;EventTrigger RoutedEvent="Loaded"&gt;
                      &lt;BeginStoryboard&gt;
                          &lt;Storyboard SpeedRatio="2.0"&gt;
                              &lt;DoubleAnimationUsingKeyFrames Duration="0:0:4.5" Storyboard.TargetName="aniBounce" Storyboard.TargetProperty="Y" RepeatBehavior="Forever"&gt;
                                  &lt;LinearDoubleKeyFrame Value="120" KeyTime="0:0:0"/&gt;
                                  &lt;SplineDoubleKeyFrame Value="260" KeyTime="0:0:2.2" KeySpline="0, 0, 0.5, 0"/&gt;
                                  &lt;LinearDoubleKeyFrame Value="260" KeyTime="0:0:2.25"/&gt;
                                  &lt;SplineDoubleKeyFrame Value="120" KeyTime="0:0:4.5" KeySpline="0, 0, 0, 0.5"/&gt;
                              &lt;/DoubleAnimationUsingKeyFrames&gt;
                              &lt;DoubleAnimationUsingKeyFrames Duration="0:0:4.5" Storyboard.TargetName="aniSquash" Storyboard.TargetProperty="ScaleX" RepeatBehavior="Forever"&gt;
                                  &lt;LinearDoubleKeyFrame Value="1" KeyTime="0:0:0"/&gt;
                                  &lt;LinearDoubleKeyFrame Value="1" KeyTime="0:0:2"/&gt;
                                  &lt;LinearDoubleKeyFrame Value="1.3" KeyTime="0:0:2.25"/&gt;
                                  &lt;LinearDoubleKeyFrame Value="1" KeyTime="0:0:2.5"/&gt;
                              &lt;/DoubleAnimationUsingKeyFrames&gt;
                              &lt;DoubleAnimationUsingKeyFrames Duration="0:0:4.5" Storyboard.TargetName="aniSquash" Storyboard.TargetProperty="ScaleY" RepeatBehavior="Forever"&gt;
                                  &lt;LinearDoubleKeyFrame Value="1" KeyTime="0:0:0"/&gt;
                                  &lt;LinearDoubleKeyFrame Value="1" KeyTime="0:0:2"/&gt;
                                  &lt;LinearDoubleKeyFrame Value="0.7" KeyTime="0:0:2.25"/&gt;
                                  &lt;LinearDoubleKeyFrame Value="1" KeyTime="0:0:2.5"/&gt;
                              &lt;/DoubleAnimationUsingKeyFrames&gt;
                          &lt;/Storyboard&gt;
                      &lt;/BeginStoryboard&gt;
                  &lt;/EventTrigger&gt;
              &lt;/Style.Triggers&gt;
          &lt;/Style&gt;
      &lt;/Window.Resources&gt;
      &lt;Grid&gt;
          &lt;Canvas Margin="0,180,0,0"&gt;
              &lt;Ellipse Canvas.Left="10" Canvas.Top="10" Width="100" Height="100" Stroke="Blue" StrokeThickness="4" Fill="Aqua" /&gt;
              &lt;Ellipse Canvas.Left="30" Canvas.Top="12" Width="60" Height="30"&gt;
                  &lt;Ellipse.Fill&gt;
                      &lt;LinearGradientBrush StartPoint="0.45,0" EndPoint="0.5, 0.9"&gt;
                          &lt;GradientStop Offset="0.2" Color="DarkMagenta" /&gt;
                          &lt;GradientStop Offset="0.7" Color="Transparent" /&gt;
                      &lt;/LinearGradientBrush&gt;
                  &lt;/Ellipse.Fill&gt;
              &lt;/Ellipse&gt;
              &lt;Ellipse Canvas.Left="33" Canvas.Top="35" Width="20" Height="20" Stroke="Blue" StrokeThickness="3" Fill="White" /&gt;
              &lt;Ellipse Canvas.Left="40" Canvas.Top="43" Width="6" Height="5" Fill="Black" /&gt;
              &lt;Ellipse Canvas.Left="68" Canvas.Top="35" Width="20" Height="20" Stroke="Blue" StrokeThickness="3" Fill="White" /&gt;
              &lt;Ellipse Canvas.Left="75" Canvas.Top="43" Width="6" Height="5" Fill="Black" /&gt;
              &lt;Path Name="mouth" Stroke="Blue" StrokeThickness="4" Data="M 35,75 Q 55,90 80,75 " /&gt;
          &lt;/Canvas&gt;
          &lt;Grid Margin="100,5,0,0" Width="75" Height="300"&gt;
              &lt;Canvas&gt;
                  &lt;Ellipse Height="40" Width="40" x:Name="theBall" Canvas.Left="16" Style="{StaticResource styleBounceAndSquash}"&gt;
                      &lt;Ellipse.Fill&gt;
                          &lt;RadialGradientBrush GradientOrigin="0.75,0.25"&gt;
                              &lt;GradientStop Color="Yellow" Offset="0.0" /&gt;
                              &lt;GradientStop Color="Red" Offset="1.0" /&gt;
                          &lt;/RadialGradientBrush&gt;
                      &lt;/Ellipse.Fill&gt;
                  &lt;/Ellipse&gt;
                  &lt;Rectangle Height="5" Canvas.Left="10" Canvas.Top="285" Width="55" Fill="Black"/&gt;
              &lt;/Canvas&gt;
          &lt;/Grid&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>The error "TargetName property cannot be set on a Style Setter. Line 20 Position 79."  </p>
  
  <p>If I can't set it in the style how do I set it?</p>