【问题标题】:C# equivalent for xaml code for animation用于动画的 xaml 代码的 C# 等效项
【发布时间】:2013-11-30 07:38:48
【问题描述】:

我使用表达式混合为名为“rect”的矩形创建了这个小动画

<Storyboard x:Name="flipanim">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)" Storyboard.TargetName="rect">
                <EasingDoubleKeyFrame KeyTime="0" Value="90"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

现在我想为运行时加载的每个列表框项(使用 itemtemplate 生成)显示此动画,如何设置列表项的动画属性。如何为列表项指定 TargetName 属性? 如果那不可能,那么我想知道如何在 C# 中转换上述代码。

【问题讨论】:

    标签: c# xaml windows-phone-7 animation windows-phone-8


    【解决方案1】:

    希望对你有帮助

    DoubleAnimation rotation = new DoubleAnimation();
                rotation.From = 0;
                rotation.To = 90;
                rotation.Duration = new Duration(TimeSpan.FromSeconds(0.5));
                Storyboard.SetTarget(rotation, rect);
                Storyboard.SetTargetProperty(rotation, new PropertyPath("(UIElement.RenderTransform).(RotateTransform.Angle)"));
                Storyboard flipanim= new Storyboard();
                flipanim.Children.Add(rotation);
                flipanim.Begin();
    

    【讨论】:

      【解决方案2】:

      您可以在 ItemTemplate 中定义 Storyboard,因此每个项目都有自己的,并为 Loaded 事件使用 EventTrigger 并使用 Action 来启动 Storyboard。将 Storyboard 定义为 DataTemplate 中第一个元素的资源,以便您可以访问命名元素(如 here)。

      【讨论】:

        猜你喜欢
        • 2017-12-18
        • 1970-01-01
        • 1970-01-01
        • 2018-11-02
        • 1970-01-01
        • 2011-12-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多