2011-08-03 73 views
2

這裏是我的用戶InvalidOperationException異常是未處理 - WPF路徑

<Grid x:Name="Grid"> 
    <Path Name="Path1" Data="M0.5,0.5 L179.5,0.5 L179.5,249.5 L0.5,249.5 z" Stretch="Fill" Stroke="Purple" StrokeThickness="1"> 
     <Path.Fill> 
      <SolidColorBrush Color="Blue" Opacity="0.4"/> 
     </Path.Fill> 
    </Path> 
    <Grid.Resources> 
     <Storyboard x:Key="Path_Ani"> 
      <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="Path1"> 
       <EasingDoubleKeyFrame KeyTime="0" Value="0"/> 
       <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="-58.515"/> 
      </DoubleAnimationUsingKeyFrames> 
      <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="Path1"> 
       <EasingDoubleKeyFrame KeyTime="0" Value="0"/> 
       <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="-129.167"/> 
      </DoubleAnimationUsingKeyFrames> 
      <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="Path1"> 
       <EasingDoubleKeyFrame KeyTime="0" Value="1"/> 
       <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0.544"/> 
      </DoubleAnimationUsingKeyFrames> 
      <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="Path1"> 
       <EasingDoubleKeyFrame KeyTime="0" Value="1"/> 
       <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0.806"/> 
      </DoubleAnimationUsingKeyFrames> 
      <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[1].(SkewTransform.AngleX)" Storyboard.TargetName="Path1"> 
       <EasingDoubleKeyFrame KeyTime="0" Value="0"/> 
       <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="5.628"/> 
      </DoubleAnimationUsingKeyFrames> 
      <PointAnimationUsingKeyFrames Storyboard.TargetProperty="(Path.Data).(PathGeometry.Figures)[0].(PathFigure.Segments)[1].(LineSegment.Point)" Storyboard.TargetName="Path1"> 
       <EasingPointKeyFrame KeyTime="0" Value="100.5,140.5"/> 
       <EasingPointKeyFrame KeyTime="0:0:0.2" Value="104.175476605516,140.5"/> 
      </PointAnimationUsingKeyFrames> 
     </Storyboard> 
    </Grid.Resources> 
</Grid> 

我這樣稱呼一樣,故事板:

private void MyTest_MouseDown(object sender, MouseButtonEventArgs e) 
{ 
    Storyboard sbdCardAnim = (Storyboard)MyTest.Grid.Resources["Path_Ani"]; 
    sbdCardAnim.Begin(); 
} 

,當我點擊我得到這個錯誤:

'[Unknown]' property does not point to a DependencyObject in path '(0).(1)[3].(2)'. 

如何解決導致此錯誤的問題?

回答

1

您的動畫預計路徑有一堆定義爲RenderTransform的轉換,但是您的路徑的實際RenderTransform似乎爲空(因爲它未定義)。

<!-- The RenderTransform which is expected looks something like this 
     (while no animation targets the third and therefore unknown transform 
     it only makes sense for it to be a RotateTransform) --> 
    <Path.RenderTransform> 
     <TransformGroup> 
      <ScaleTransform /> 
      <SkewTransform /> 
      <RotateTransform /> 
      <TranslateTransform /> 
     </TransformGroup> 
    </Path.RenderTransform> 

在PointAnimation的路徑也似乎不符合實際的數據路徑是仍然會有,如果按預期的RenderTransform定義錯誤。