如何在 WPF 中为 Margin 属性设置动画 [英] How to animate Margin property in WPF

查看:97
本文介绍了如何在 WPF 中为 Margin 属性设置动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想移动矩形对象的动画以在 x 轴上移动它.我是 WPF 动画的新手,从以下内容开始:

I want to move animate an rectangle object to move it in x-axis. I am new to WPF animation, started out with the following:

<Storyboard x:Key="MoveMe">
    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" 
                                   Storyboard.TargetName="GroupTileSecond"
                                   Storyboard.TargetProperty="(**Margin.Left**)">

        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="**134, 70,0,0**" />
        <SplineDoubleKeyFrame KeyTime="00:00:03" Value="**50, 70,0,0**" />
    </DoubleAnimationUsingKeyFrames>
</Storyboard>

显然发现我不能使用 Margin.Left 作为 Storyboard.TargetProperty 或使用 134,70,0,0 在 Value 属性中.

Obviously found out that I cant use Margin.Left as Storyboard.TargetProperty or use 134,70,0,0 in Value property.

那么,如何在 XAML WPF 中移动对象.

So, how do I move an object in XAML WPF.

推荐答案

Margin 属性可以使用 ThicknessAnimation

<Storyboard >
     <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" BeginTime="00:00:00">
        <SplineThicknessKeyFrame KeyTime="00:00:00" Value="134, 70,0,0" />
        <SplineThicknessKeyFrame KeyTime="00:00:03" Value="50, 70,0,0" />
     </ThicknessAnimationUsingKeyFrames>
</Storyboard>

这篇关于如何在 WPF 中为 Margin 属性设置动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆