title: How to set Storyboard.SetTargetProperty in Code behind?
body: <p>I am trying to convert XAML Storyboard to code behind Storyboard. But I get an exception </p>
  
  <pre><code>Cannot resolve all property references in the property path
    '(UIElement.RenderTransform).(myTransformGroup.Children)[1].(TranslateTransform.Y)'.
    Verify that applicable objects support the properties.  
  </code></pre>
  
  <p>I searched several websites but they also do this the same way. I don`t understand where I am going wrong. </p>
  
  <p>XAML: </p>
  
  <pre><code>&lt;Storyboard x:Key="Storyboard1"&gt;
          &lt;DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="r1"&gt;
              &lt;EasingDoubleKeyFrame KeyTime="0" Value="1"/&gt;
              &lt;EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="0.828"/&gt;
              &lt;EasingDoubleKeyFrame KeyTime="0:0:1" Value="0.828"/&gt;
          &lt;/DoubleAnimationUsingKeyFrames&gt;
  
          &lt;DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="r1"&gt;
              &lt;EasingDoubleKeyFrame KeyTime="0" Value="0"/&gt;
              &lt;EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="8.621"/&gt;
              &lt;EasingDoubleKeyFrame KeyTime="0:0:1" Value="8.621"/&gt;
          &lt;/DoubleAnimationUsingKeyFrames&gt;
      &lt;/Storyboard&gt;
  </code></pre>
  
  <p>C# Code:</p>
  
  <pre><code>  public void myAnimation(Rectangle myRectangle)
      {
          this.UnregisterName(myRectangle.Name);
          ScaleTransform myScaleTransform = new ScaleTransform();
          TranslateTransform myTranslateTransform = new TranslateTransform();
          TransformGroup myTransformGroup = new TransformGroup();
          myTransformGroup.Children.Add(myScaleTransform);
          myTransformGroup.Children.Add(myTranslateTransform);
          myRectangle.RenderTransform = myTransformGroup;
          this.RegisterName(myRectangle.Name, myTransformGroup);
  
          DoubleAnimationUsingKeyFrames myDoubleAnimationUsingKeyFrames = new DoubleAnimationUsingKeyFrames();
          EasingDoubleKeyFrame myEasingDoubleKeyFrame = new EasingDoubleKeyFrame();
          Storyboard myStoryboard = new Storyboard();
  
          Storyboard.SetTargetName(myDoubleAnimationUsingKeyFrames, myRectangle.Name);
          Storyboard.SetTargetProperty(myDoubleAnimationUsingKeyFrames, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"));
  
          myEasingDoubleKeyFrame.KeyTime = KeyTime.FromPercent(0);
          myEasingDoubleKeyFrame.Value = 1;
          myDoubleAnimationUsingKeyFrames.KeyFrames.Add(myEasingDoubleKeyFrame);
  
          myEasingDoubleKeyFrame.KeyTime = KeyTime.FromPercent(0.4);
          myEasingDoubleKeyFrame.Value = 0.828;
          myDoubleAnimationUsingKeyFrames.KeyFrames.Add(myEasingDoubleKeyFrame);
  
          myEasingDoubleKeyFrame.KeyTime = KeyTime.FromPercent(1);
          myEasingDoubleKeyFrame.Value = 0.828;
          myDoubleAnimationUsingKeyFrames.KeyFrames.Add(myEasingDoubleKeyFrame);
  
          myStoryboard.Children.Add(myDoubleAnimationUsingKeyFrames);
  
          Storyboard.SetTargetName(myDoubleAnimationUsingKeyFrames, myRectangle.Name);
          Storyboard.SetTargetProperty(myDoubleAnimationUsingKeyFrames, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.X)"));
  
          myEasingDoubleKeyFrame.KeyTime = KeyTime.FromPercent(0);
          myEasingDoubleKeyFrame.Value = 0;
          myDoubleAnimationUsingKeyFrames.KeyFrames.Add(myEasingDoubleKeyFrame);
  
          myEasingDoubleKeyFrame.KeyTime = KeyTime.FromPercent(0.4);
          myEasingDoubleKeyFrame.Value = -17.5;
          myDoubleAnimationUsingKeyFrames.KeyFrames.Add(myEasingDoubleKeyFrame);
  
          myEasingDoubleKeyFrame.KeyTime = KeyTime.FromPercent(1);
          myEasingDoubleKeyFrame.Value = 165.5;
          myDoubleAnimationUsingKeyFrames.KeyFrames.Add(myEasingDoubleKeyFrame);
  
          myStoryboard.Children.Add(myDoubleAnimationUsingKeyFrames);
  
          myStoryboard.Begin(myRectangle);
  
      }
  </code></pre>
  
  <p>I guess the problem is in <b>Storyboard.SetTargetProperty</b></p>