user interface - WPF forcing GUI update using Dipatcher -
i need show custom control (a clock rotating hands) , replace mouse cursor, problem if write:
me.gridscreen.visibility = visibility.visible ' operations takes 1 second me.gridscreen.visibility = visibility.hidden (gridscreen grid contains user-control)
obviously can see nothing, because update of ui happens @ end of procedure. have tried me.updatelayout(), doesn't work.
i have tryed use dispacker in many way none works :-(
this lost attempt:
(ucurclock usercontrol, gridscreen grid placed @ top-level in window, trasparent background, contains usercontrol)
private sub showclock() dim thread = new system.threading.thread(addressof showclockintermediate) thread.start() end sub private sub hideclock() dim thread = new system.threading.thread(addressof hideclockintermediate) thread.start() end sub private sub showclockintermediate() me.dispatcher.begininvoke(dispatcherpriority.normal, _ new action(addressof showclockfinale)) end sub private sub hideclockintermediate() me.dispatcher.begininvoke(dispatcherpriority.normal, _ new action(addressof hideclockfinale)) end sub private sub showclockfinale() dim pt point = mouse.getposition(nothing) me.ucurclock.margin = new thickness(pt.x - 9, pt.y - 9, 0, 0) me.gridscreen.visibility = visibility.visible me.cursor = cursors.none me.updatelayout() end sub private sub hideclockfinale() me.gridscreen.visibility = visibility.hidden me.cursor = cursors.arrow me.updatelayout() end sub private sub u_mousemove(byval sender system.object, _ byval e mouseeventargs) handles gridscreen.mousemove dim pt point = e.getposition(nothing) me.ucurclock.margin = new thickness(pt.x - 9, pt.y - 9, 0, 0) e.handled = true end sub private sub u_mouseenter(byval sender system.object, _ byval e mouseeventargs) handles gridscreen.mouseenter me.ucurclock.visibility = visibility.visible e.handled = true end sub private sub u_mouseleave(byval sender system.object, _ byval e mouseeventargs) handles gridscreen.mouseleave me.ucurclock.visibility = visibility.hidden e.handled = true end sub
pileggi
the problem not composition of messages being executed on dispatcher, it's you're executing long-running work on dispatcher @ all. must ensure long-running/potentially blocking operations executed on background thread. easiest way backgroundworker
component.
excuse c#:
var backgroundworker = new backgroundworker(); backgroundworker.dowork += delegate { // long running work goes here }; backgroundworker.runworkercompleted += delegate { // change cursor normal here }; // change cursor busy here // kick off background task backgroundworker.runworkerasync();
Comments
Post a Comment