我有以下动画,在某些事件中应该导致按钮从左向右移动:
<UserControl.Resources>
<Storyboard x:Key="Storyboard1">
<DoubleAnimation Storyboard.TargetName="Studio" Storyboard.TargetProperty="Opacity" From="0" To="{Binding StudioOpacityValue}" Duration="0:0:2"/>
<DoubleAnimation Storyboard.TargetName="Studio" Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)" From="0" To="500" Duration="0:0:2">
<DoubleAnimation.EasingFunction>
<CubicEase EasingMode="EaseInOut"/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
</UserControl.Resources>
<Grid Name="mainGrid" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="FadeInMainButtonsAfterImport" SourceObject="{Binding Mode=OneWay}">
<ei:ControlStoryboardAction Storyboard="{StaticResource Storyboard1}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Button x:Name ="Studio" Grid.Row="33" Grid.Column="57" Grid.ColumnSpan="36" Grid.RowSpan="36" IsEnabled="{Binding IsStudioEnabled}" Opacity="{Binding StudioOpacityValue}" >
<Button.RenderTransform>
<TranslateTransform/>
</Button.RenderTransform>
</Button>
<Grid>
但没有任何反应。可能是什么问题?
答案 0 :(得分:3)
你关闭了,但我们需要调整一些事情。
在按钮上打开属性,以便了解我们正在处理的内容。现在你正在瞄准对象,而不是转换。所以我们做了类似的事情;
<Button x:Name="Studio"
Grid.Row="33" Grid.Column="57"
Grid.ColumnSpan="36" Grid.RowSpan="36"
IsEnabled="{Binding IsStudioEnabled}"
Opacity="{Binding StudioOpacityValue}" >
<Button.RenderTransform>
<TranslateTransform x:Name="StudioTranslate" X="0"/>
</Button.RenderTransform>
</Button>
您已经使用DoubleAnimation关闭了,但是之间存在关键帧以便发生该动画,因此可以处理那些讨厌的样条插值;
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="StudioTranslate"
Storyboard.TargetProperty="X" Duration="0:0:2">
<SplineDoubleKeyFrame KeyTime="0:0:2" Value="500" />
</DoubleAnimationUsingKeyFrames>
这通常是我如何做到的。希望它有所帮助,欢呼。
<强>附录:强>
要将缓动函数与DoubleAnimationUsingKeyFrame相关联,我们将从样条曲线转换为EasingDoubleKeyFrame:
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="StudioTranslate"
Storyboard.TargetProperty="X" Duration="0:0:2">
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="500">
<EasingDoubleKeyFrame.EasingFunction>
<CubicEase EasingMode="EaseInOut"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
答案 1 :(得分:0)
试试这个(我在按钮内移动了触发器):
<UserControl.Resources>
<Storyboard x:Key="Storyboard1">
<DoubleAnimation Storyboard.TargetName="Studio" Storyboard.TargetProperty="Opacity" From="0" To="{Binding StudioOpacityValue}" Duration="0:0:2"/>
<DoubleAnimation Storyboard.TargetName="Studio" Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)" From="0" To="500" Duration="0:0:2">
<DoubleAnimation.EasingFunction>
<CubicEase EasingMode="EaseInOut"/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
</UserControl.Resources>
<Grid Name="mainGrid" >
<Button x:Name ="Studio" Grid.Row="33" Grid.Column="57" Grid.ColumnSpan="36" Grid.RowSpan="36" IsEnabled="{Binding IsStudioEnabled}" Opacity="{Binding StudioOpacityValue}" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="FadeInMainButtonsAfterImport" SourceObject="{Binding Mode=OneWay}">
<ei:ControlStoryboardAction Storyboard="{StaticResource Storyboard1}"/>
</i:EventTrigger>
<Button.RenderTransform>
<TranslateTransform/>
</Button.RenderTransform>
</Button>
<Grid>