views:

113

answers:

2

Hi all. 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.

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?

A: 

The Storyboard object has a 'Completed' event you can subscribe to. It will be called when the animation is done. This what you are looking for?

Basically I think you want "ProcExpandCollapse.Completed +=" (then hit tab a view times, VS will generate a snippet for you)

Peanut
No, I am looking to wait until the *rendering* is completed.
Adam S
A: 

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);

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).

Adam S