等待动画,渲染完成-XAML和C# [英] Wait for animation, render to complete - XAML and C#

查看:103
本文介绍了等待动画,渲染完成-XAML和C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某种情况下,我正在对XAML应用程序的一部分进行动画处理,并且需要等待动画和渲染完成后才能继续执行代码.到目前为止,我的函数的末尾看起来像:

I have a situation where I am animating part of my XAML application, and I need to wait for the animation AND rendering to complete before I can move on in my code. So far the tail end of my function looks like:

    ProcExpandCollapse.Begin();
    while (ProcExpandCollapse.GetCurrentState() != ClockState.Stopped) { }
}

从理论上讲,这将等到动画完成为止.但是,它不会等到渲染完成后才能绘制-绘制应用程序的线程可能仍未重新绘制动画.

Which, in theory, will wait until the animation is finished. But it will not wait until the rendering is finished - the thread drawing the application might still not have re-drawn the animation.

动画正在扩展UIElement,然后我的代码的下一部分使用其渲染的大小来做一些事情.那么我的问题是,我该如何等待UI元素重新渲染之后才能继续?

The animation is expanding a UIElement, and then the next part of my code uses it's rendered size to do some things. My question then is, how do I wait until my UI Element is re-rendered before moving on?

推荐答案

我终于找到了答案(尽管我必须为咨询服务付费)!本质上,我最终要做的是将使用渲染控件的代码以非常低的优先级放到控件调度程序的队列中,这样它自然就可以在处理该任务之前进行渲染.例如:

I finally found an answer (although I had to pay for consulting services)! Essentially what I ended up doing was putting the bit of code which uses the rendered controls on the control dispatcher's queue with very low priority, so that it naturally renders before handling that task. For example:

mycontrol.Dispatcher.BeginInvoke((Action)delegate{textbox1.Text = "Grazie";});
mycontrol.Dispatcher.Invoke((Action)delegate{GetScreenshot();}, DispatcherPriority.Background);

然后将在调用并完成GetScreenshot之后继续处理代码,这将在渲染完成之后进行(因为渲染的优先级高于背景).

The code will then procede after GetScreenshot is called and finished, which will be after the rendering is completed (because rendering has higher priority than background).

这篇关于等待动画,渲染完成-XAML和C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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