0

I'm overriding WPF's OnRender to draw complex graphics. This may rarely take a long time. I would like to indicate to the user that the app did not crash, but is "merely" taking a long time to render.

How would I do that? It seems not possible to modify the UI in any way during the OnRender call.

mafu
  • 31,798
  • 42
  • 154
  • 247
  • Your last statement is correct, you cannot modify the UI while you are modifying the UI. Those two operations would be on the same thread, and therefore sequential, not asynchronous. – Stewbob Mar 18 '17 at 20:01

2 Answers2

0

You are talking about placing a "Busy Indicator" on top of your drawing.

Just place a half transparent grid on top with the writing "Loading..." and you're done.

Bind its visibility to some bool that you update once when entering the complex rendering, and once when finished.

Or put a spinning Ellipse with gradient background if you want to see motion..

Mishka
  • 508
  • 3
  • 5
0

Since the OnRender method will execute on the UI thread you cannot do anything else such as displaying an interactive ProgressBar or respond to user input during the execution of your code.

What you can do is to pop up a new window that launches in a separate thread and display this one right before you begin to draw your complex graphics.

Please refer to my answer in the following similar question for more information about this.

Wait screen during rendering UIElement in WPF

Once the OnRender method has returned you then close the temporary "loading" window:

Can I stop WPF from executing UI actions out of the order in my code

Community
  • 1
  • 1
mm8
  • 163,881
  • 10
  • 57
  • 88