问题
I am using some 3rd party components that take some time (~3-5s) to render - after profiling I've come to conclusion that most of the time is wasted in MeasureOverride and Render methods of those controls... I cannot edit source code of those components. The problem is .. can I display a busy indicator while the interface is being 'drawn' ? Is it possible in WPF?
回答1:
No you can't, well, not in a good way.
The UI thread is busy rendering - drawing the busy indicator would require that same thread to draw the indicator instead.
Now, you can create a second window (maybe semi-transparent) from another thread and place that window on top of your frozen window, but that is very difficult to get right, you have to deal with things like the user moving the window (and you will never know the window moved because the thread that accept the move notifications is busy) or other application poping up between your two windows
Also this is likely to interfere with the first window drawing and generally just has to many corner cases to ever get right.
来源:https://stackoverflow.com/questions/3653668/busy-indicator-during-long-wpf-interface-drawing-operation