I have a small program written to manipulate textual data then write it to a text file. A typical workflow is this:
Here's the problem. When pasting a lot of data (600,000 lines etc), it takes a little while till the data actually appears in the textbox even though the paste event happens immediately. I'm assuming that the delay is a rendering issue.
When the paste event fires I pop up a status window alerting the user that pasting has begun.
I want to know when the paste/redraw has finished so I can close the status window but have been unable to find any info on the subject.
I'm probably googling the wrong stuff since all I can find is work arounds for forcing a windows to redraw before continuing code execution. This seems like an ugly hack to me. I'd rather simply listen for a "render completed" event. Maybe there isn't anything like that.
Have a look here: http://geekswithblogs.net/ilich/archive/2012/10/16/running-code-when-windows-rendering-is-completed.aspx
WPF is full of surprises. It makes complicated tasks easier, but at the same time overcomplicates easy task as well. A good example of such overcomplicated things is how to run code when you’re sure that window rendering is completed. Window Loaded event does not always work, because controls might be still rendered. I had this issue working with Infragistics XamDockManager. It continued rendering widgets even when the Window Loaded event had been raised. Unfortunately there is not any “official” solution for this problem.
But there is a trick. You can execute your code asynchronously using Dispatcher class.
Dispatcher.BeginInvoke(new Action(() => Trace.WriteLine("DONE!",
"Rendering")), DispatcherPriority.ContextIdle, null);
This code should be added to your Window Loaded event handler. It is executed when all controls inside your window are rendered. Seems to address your issue
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With