动画边距/厚度 [英] Animate Margin / Thickness

查看:98
本文介绍了动画边距/厚度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是以为我已经知道WPF和XAML语法的工作原理....
wrooong。

I just thought I already know how WPF and XAML Syntax works.... wrooong.

我收到消息:

'WithEvents' variables can only be typed as classes, interfaces or type parameters with class constraints.

请问,您知道为什么这个语法是错误的吗?

Please, do you know why this syntax is wrong?

我需要将单个值用作双精度值。

I need to use the single value as double. It works later with an storyboard in codebehind.

关于

我只想使用位置和大小的演示图板为红色矩形设置动画。也许XAML是正确的解决方案?

I just want to animate the Red rectangle with a storyboard in location and size. Perhaps XAML is the right solution anyway?

推荐答案

要设置厚度的动画效果,请使用这样的Storyboard(来自msdn示例):

To animate thickness, use a Storyboard like this (from msdn example):

<BeginStoryboard>
    <Storyboard>    
      <!-- BorderThickness animates from left=1, right=1, top=1, and bottom=1 to
      left=28, right=28, top=14, and bottom=14 over one second. -->
      <ThicknessAnimation
        Storyboard.TargetProperty="BorderThickness"
        Duration="0:0:1.5" FillBehavior="HoldEnd" From="1,1,1,1" To="28,14,28,14" />
    </Storyboard>
  </BeginStoryboard>

实际上,要对使用 w,x,y,z值的任何属性设置动画一个ThicknessAnimation

Actually, to animate any property that takes values as "w,x,y,z" you use a ThicknessAnimation

在我看来,您想要做的就是将红色矩形向右移动。

It seems to me that what you want to do is move the red rectangle to the right.

在那种情况下,将整个内容放在 Canvas 中,并在红色矩形的位置上使用DoubleAnimation。

In that case, put the whole thing in a Canvas and use a DoubleAnimation on the red rectangle's position.

无论哪种方式,您得到的错误都不是您提供的一小段代码,如果您想解决该错误,请提供更多代码。

Either way, the error you're getting does not come from the small piece of code you provided, if you want to adress that, please provide use with more code.

编辑:由于ThicknessAnimation在WP7上似乎不可用,请尝试以下操作:

since ThicknessAnimation seems to be not available on WP7, try this instead:

<BeginStoryboard>
    <Storyboard>    
      <DoubleAnimation
        Storyboard.TargetProperty="BorderThickness.Top"
        Duration="0:0:1.5" To="15" />
      <DoubleAnimation
        Storyboard.TargetProperty="BorderThickness.Left"
        Duration="0:0:1.5" To="25" />
    </Storyboard>
  </BeginStoryboard>

这篇关于动画边距/厚度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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