gpt4 book ai didi

c# - 如何在 Silverlight 中为 zIndex 属性设置动画?

转载 作者:行者123 更新时间:2023-11-30 21:08:06 27 4
gpt4 key购买 nike

Doubleanimation 不起作用,因为 typ 是一个整数。有没有 Integeranimation 类?或者以不同的方式进行。我对静态动画不感兴趣,但对事件驱动(最好程序化)动画。

public static void Swap(UIElement ui1, UIElement ui2, double seconds)
{
var z2 = (int)ui1.GetValue(Canvas.ZIndexProperty);
var z3 = (int)ui2.GetValue(Canvas.ZIndexProperty);
DoubleAnimation da1 = new DoubleAnimation();
DoubleAnimation da2 = new DoubleAnimation();
Duration d = new Duration(TimeSpan.FromSeconds(seconds));
da1.Duration = d;
da2.Duration = d;
Storyboard sb = new Storyboard();
Storyboard.SetTarget(da1, ui1);
Storyboard.SetTarget(da2, ui2);
Storyboard.SetTargetProperty(da1, new PropertyPath("(Canvas.ZIndex)"));
Storyboard.SetTargetProperty(da2, new PropertyPath("(Canvas.ZIndex)"));
sb.Duration = d;
sb.Children.Add(da1);
sb.Children.Add(da2);
da1.To = (double)z3;
da2.To = (double)z2;
sb.Begin();



}

private void Btn1_Click_1(object sender, RoutedEventArgs e)
{
var z2 = (int)Image2.GetValue(Canvas.ZIndexProperty);
var z3 = (int)Image3.GetValue(Canvas.ZIndexProperty);

Swap(Image2, Image3, 3);

}

最佳答案

您可以使用 ObjectAnimationUsingKeyFrames 和 DiscreteObjectKeyFrame 为离散值设置动画。

<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Canvas.ZIndex)" Storyboard.TargetName="MyObject">
<DiscreteObjectKeyFrame KeyTime="0" Value="250"/>
</ObjectAnimationUsingKeyFrames>

或者您可以在代码中完成。

关于c# - 如何在 Silverlight 中为 zIndex 属性设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9879399/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com