Исключительная ситуация InvalidOperationException - WPF Path - PullRequest
2 голосов
/ 04 августа 2011

Вот мой UserControl

<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>

И я называю StoryBoard так:

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 Ответ

1 голос
/ 04 августа 2011

Ваша анимация ожидает, что путь будет иметь набор преобразований, определенных как 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 определен, как и ожидалось.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...