我想使用ObjectAnimationUsingKeyFrames在winrt中爲我的一個控件創建動畫。在一段時間內,控制應該從保證金=「0,0,-500,0」移動到保證金=「0,0,0,0」。我有以下代碼。它幾乎可以工作,但一切都立即發生,沒有看到動畫或平滑過渡。ObjectAnimationUsingKeyFrames - WinRT中位置之間的平滑過渡
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="NameOfControl"
Storyboard.TargetProperty="(FrameworkElement.Margin)"
Duration="00:00:00.5">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Thickness>0,0,-500,0</Thickness>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="00:00:0.5">
<DiscreteObjectKeyFrame.Value>
<Thickness>0,0,0,0</Thickness>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
- 你有任何線索,爲什麼它不工作嗎?
- 你有另一種方式 如何將控制從某個面板外部移動到其默認的 位置?在我看來,使用保證金是它的一種破解。
我不是一個WinRT的專家,但是這是我想嘗試:不是動畫的'Margin',把你的控制了'Canvas'內使用'DoubleAnimation'動畫'Canvas.Left' 。你可以在Charles Petzold的文章[「Animating Attached Properties」中找到一個例子](http://www.charlespetzold.com/blog/2007/09/080231.html)。所有必需的類似乎在WinRT中都可用。 –