Wpf 设置用户控件的动画
我已经在我的两个UserControls之一上使用Blend制作了一个不透明动画,已删除,并从中删除Storyboard.TargetName,将其放置在App.xaml中,看起来像:Wpf 设置用户控件的动画,wpf,rendertransform,Wpf,Rendertransform,我已经在我的两个UserControls之一上使用Blend制作了一个不透明动画,已删除,并从中删除Storyboard.TargetName,将其放置在App.xaml中,看起来像: <Storyboard x:Key="Loaded"> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" > <EasingDoubleKeyFrame
<Storyboard x:Key="Loaded">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" >
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:3" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<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>
它按预期工作。对于transform动画,除上述内容外,我还删除了TransformGroup,现在它看起来像:
<Storyboard x:Key="Loaded">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" >
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:3" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<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>
如何解决此问题?您需要向UserControl添加一个RenderTransform,它类似于Storyboard.TargetProperty,该属性当前需要一个TransformGroup,其中第四个子项为TranslateTransform 将以下代码添加到两个UserControl中的每一个:
<UserControl x:Class="YourUserControl"
...>
<UserControl.RenderTransform>
<TransformGroup>
<RotateTransform/>
<ScaleTransform/>
<SkewTransform/>
<TranslateTransform/>
</TransformGroup>
</UserControl.RenderTransform>
有了这一点,我会有另一个问题,但津德克斯解决了这个问题。我可以在代码中精确地指定UserControl.RenderTransform.TranslateTransform,而不是在所有UserControl中添加这8行吗?接下来,我创建了一个TransformGroup,将其设置为UserControl的RenderTransform,以避免UserControl中的xaml。