为什么这个翻译动画不起作用



我有以下动画,在某些事件中应该会导致按钮从左向右移动:

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

但什么也没发生。可能是什么问题?

您很接近,但我们需要调整几点。

打开你的按钮上的财产,这样它就知道我们在处理什么。现在您的目标是对象,而不是变换。所以我们做了一些类似的事情;

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

我通常都是这样做的。希望有帮助,干杯。

附录:

为了将缓和函数与DoubleAnimationUsingKeyFrames关联,我们从样条线翻转到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>

试试这个(我已经在按钮中移动了触发器):

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

相关内容

  • 没有找到相关文章

最新更新