Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在WPF中的两个单独动画之间临时暂停 我是Windows演示文稿基础和C语言的初学者。作为一个启动项目,我决定在WPF中创建,或者说重新创建“西蒙”游戏_C#_Wpf_Xaml - Fatal编程技术网

C# 如何在WPF中的两个单独动画之间临时暂停 我是Windows演示文稿基础和C语言的初学者。作为一个启动项目,我决定在WPF中创建,或者说重新创建“西蒙”游戏

C# 如何在WPF中的两个单独动画之间临时暂停 我是Windows演示文稿基础和C语言的初学者。作为一个启动项目,我决定在WPF中创建,或者说重新创建“西蒙”游戏,c#,wpf,xaml,C#,Wpf,Xaml,西蒙游戏图片: 下面是处理闪烁的部分代码: { if (watchMode) { // In watch mode the user can't click on the simon button. return; } DoubleAnimation opacityClickAnimation = new Doubl

西蒙游戏图片:

下面是处理闪烁的部分代码:

        {

            if (watchMode)
            {
                // In watch mode the user can't click on the simon button.
                return;
            }

            DoubleAnimation opacityClickAnimation = new DoubleAnimation
            {
                From = 0,
                To = 1,
                Duration = new Duration(TimeSpan.FromSeconds(0.3)),
                AutoReverse = true

            };
            List<int> clickList = new List<int>();

            Path objButton = (Path)sender;

            // Switching all the possible options - determining them by name.
            // This method is much easier than creating 4 different events.
            switch (objButton.Name)
            {
                case "RedBlock":
                    RedBlockGradient.BeginAnimation(RadialGradientBrush.OpacityProperty, opacityClickAnimation);
                    await Task.Delay(taskDelay);
                    clickList.Add(redButtonValue);

                    lightValueClicked = redButtonValue;

                    break;
                case "BlueBlock":
                    BlueBlockGradient.BeginAnimation(RadialGradientBrush.OpacityProperty, opacityClickAnimation);
                    await Task.Delay(taskDelay);
                    clickList.Add(blueButtonValue);

                    lightValueClicked = blueButtonValue;

                    break;
                case "OrangeBlock":
                    OrangeBlockGradient.BeginAnimation(RadialGradientBrush.OpacityProperty, opacityClickAnimation);
                    await Task.Delay(taskDelay);
                    clickList.Add(orangeButtonValue);

                    lightValueClicked = orangeButtonValue;

                    break;
                case "GreenBlock":
                    GreenBlockGradient.BeginAnimation(RadialGradientBrush.OpacityProperty, opacityClickAnimation);
                    await Task.Delay(taskDelay);
                    clickList.Add(greenButtonValue);

                    lightValueClicked = greenButtonValue;

                    break;

            }
上面是闪光灯的不透明度动画

所以在西蒙身上,每一种颜色都会闪烁,其间总是有一个小小的停顿。首先,我不完全确定如何解决这个问题我现在正在做的工作有效,但我想知道是否有其他替代方法。我对异步方法和类似的东西不感兴趣——我的程序是同步的——我正在寻找一种在闪烁之间暂停的同步替代方法


我也意识到这段代码并不完美-我应该使用任务而不是异步void方法-这就是我寻找同步替代方法的原因

您可以通过附加到
已完成的事件对动画进行排队:

<Storyboard x:Name="MyStoryboard" Completed="MyStoryboardCompleted" ...>

这回答了你的问题吗?如果您喜欢在代码中创建动画,我在过去使用Artefact Animator(而不是内置方法)时会玩得更好:-它可以让您更好地控制计时。。。虽然我不确定这些年后它是否仍然有效。你正在使用异步动画,如果你不使用异步的原因是不学习异步,那么这是一个非常糟糕的决定。你好,Bizhan,我正在学习异步编程课程。谢谢
<Storyboard x:Name="MyStoryboard" Completed="MyStoryboardCompleted" ...>
private async void MyStoryboardCompleted(object sender, EventArgs e)
{
    await Task.Delay(delay); // wait
    StartMyNextAnimation();  // start next
}