0

我创建了一个 MainMenu 和两个动画:ZoomIn 和 ZoomOut。MainMenu 将充满 Canvas,每个都包含图标。我想要做的是单击一个按钮,当前可见面板会随着 ZoomOut 消失,而单击的面板会随着 ZoomIn 出现。

到目前为止,我已经设法使用以下代码从代码后面调用动画:

Dim ZoomOut As Storyboard = DirectCast(FindResource("storyZoomOut"), Storyboard)
    ZoomOut.Begin()

但现在我想让特定的控件设置动画。是否可以同时为两个不同的控件设置动画?同时像 Canvas1 ZoomOut 和 Canvas2 ZoomIn 一样?

<Storyboard x:Key="storyZoomOut">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="pnlCompras">
            <EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="0.8"/>
            <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0.6"/>
            <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0.4"/>
            <EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="0.2"/>
            <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0.0"/>
        </DoubleAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="pnlCompras">
            <EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="1.04"/>
            <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="1.09"/>
            <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="1.15"/>
            <EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="1.3"/>
        </DoubleAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="pnlCompras">
            <EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="1.04"/>
            <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="1.09"/>
            <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="1.15"/>
            <EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="1.3"/>
        </DoubleAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="pnlCompras">
            <EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="0"/>
        </DoubleAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="pnlCompras">
            <EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="0"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>

感谢你的帮助!

4

2 回答 2

1

您可以从 Storyboard 中的所有动画中删除该Storyboard.TargetName="pnlCompras"设置,然后通过Storyboard.Begin(FrameworkElement)在任何控件上运行 Storyboard 。

Dim ZoomOut As Storyboard = DirectCast(FindResource("storyZoomOut"), Storyboard)
ZoomOut.Begin(someControl)
于 2013-03-16T16:33:05.913 回答
0

您也可以在活动中使用这些行

Dim ZoomOut As Storyboard = DirectCast(FindResource("storyZoomOut"), Storyboard)
ZoomOut.Begin( --Control-- )

或者

用这条线测试

DirectCast(FindResource("storyZoomOut"), Animation.Storyboard).Begin()
于 2017-09-06T00:54:08.470 回答