0

我在一个我的两个上使用 Blend 制作了一个不透明动画UserControls,已删除<UserControl.Resources><UserControl.Triggers>然后Storyboard.TargetName将其放入其中App.xaml,它看起来像:

<Storyboard x:Key="Loaded">
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" >
        <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
        <EasingDoubleKeyFrame KeyTime="0:0:3" Value="1"/>
    </DoubleAnimationUsingKeyFrames>
</Storyboard>

当我在设置Contentmy之前用这样的代码调用它时ContentControl

Storyboard sb = FindResource("Loaded") as Storyboard;
sb.begin(uc1);
content.Content = uc1;

//and

Storyboard sb = FindResource("Loaded") as Storyboard;
sb.begin(uc2);
content.Content = uc2;

它按预期工作。TransformGroup对于变换动画,除了上面的那些,我也删除了,现在它看起来像:

<Storyboard x:Key="Unloaded">
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
        <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
        <EasingDoubleKeyFrame KeyTime="0:0:3" Value="-800"/>
    </DoubleAnimationUsingKeyFrames>
</Storyboard>

如果我以同样的方式调用它,我会收到此错误:

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

如何解决问题?

4

1 回答 1

1

您将需要向您的 UserControl 添加一个 RenderTransform,它类似于 Storyboard.TargetProperty,它当前需要一个带有第 4 个子项的 TransformGroup 作为 TranslateTransform。

将以下代码添加到两个 UserControl 中的每一个中:

<UserControl x:Class="YourUserControl"
        ...>

    <UserControl.RenderTransform>
        <TransformGroup>
            <RotateTransform/>
            <ScaleTransform/>
            <SkewTransform/>
            <TranslateTransform/>
        </TransformGroup>
    </UserControl.RenderTransform>
于 2019-10-18T09:31:29.910 回答