如何在C#代码中运行Xaml动画 [英] How Run Xaml Animation In C# Code

查看:77
本文介绍了如何在C#代码中运行Xaml动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的ResourceDictionary中有动画,但是我想在C#代码中调用动画.此ResourceDictionary添加到我的资源应用程序

示例:

I Have Animation In My ResourceDictionary But I Want Call Animation In My C# Code. This ResourceDictionary Add To My Resources App

Example:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<BeginStoryboard x:Key="PuzzleFall">
                <Storyboard Storyboard.TargetName="RenderT" Storyboard.TargetProperty="X">
                    <DoubleAnimationUsingKeyFrames  Duration="0:0:3" BeginTime="0:0:0">
                        <SplineDoubleKeyFrame Value="0" KeySpline="1 0,0.95 0" KeyTime="0:0:3"/>
                    </DoubleAnimationUsingKeyFrames>

                    <DoubleAnimationUsingKeyFrames BeginTime="0:0:3.06" Duration="0:0:1.5">
                        <SplineDoubleKeyFrame Value="50" KeySpline="0 1,0 1" KeyTime="0:0:1.5"/>
                    </DoubleAnimationUsingKeyFrames>

                    <DoubleAnimationUsingKeyFrames BeginTime="0:0:3.08" Duration="0:0:1">
                        <SplineDoubleKeyFrame Value="0" KeySpline="1 0,1 0" KeyTime="0:0:1"/>
                    </DoubleAnimationUsingKeyFrames>

                    <DoubleAnimationUsingKeyFrames BeginTime="0:0:4.1" Duration="0:0:1">
                        <SplineDoubleKeyFrame Value="15" KeySpline="0 1,0 1" KeyTime="0:0:1"/>
                    </DoubleAnimationUsingKeyFrames>

                    <DoubleAnimationUsingKeyFrames BeginTime="0:0:4.15" Duration="0:0:0.5">
                        <SplineDoubleKeyFrame Value="0" KeySpline="1 0,1 0" KeyTime="0:0:0.5"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>

</BeginStoryboard>
</ResourceDictionary>



然后我想用C#代码运行此动画.

谢谢.



Then I Want Run This Animation In C# Code.

Thanks.

推荐答案

此处所述 a> [ ^ ],类似
Storyboard sbdLabelRotation
    = (Storyboard) FindResource( "sbdLabelRotation" );

  sbdLabelRotation.Begin( this );

应该可以解决问题.


查看在C#中使用资源文件"以下文章的"部分,
在WPF中使用资源字典 [
Look into the "Using Resource Files in C#" section of the below article,
Using a Resource Dictionary in WPF[^]


这篇关于如何在C#代码中运行Xaml动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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