c# - Show MessageBox inside Pastinghandler WPF -
c# - Show MessageBox inside Pastinghandler WPF -
i have dialog user can edit fields. there 3 specific ones have validation. these fields created pastinghandler following:
dataobject.addpastinghandler(mytextbox, numericvalidatorhandler); when seek show messagebox within handler exception. seems paste runs in different thread...
my workaround @ moment utilize backgroundworker , set 2 events dowork , runworkercompleted.
in first 1 set result args pass numericvalidatorhandler 'argument' property
'numericvalidatorhandler'
bw.runworkerasync(args); ....
'doworkhandler'
e.result = e.argument; ....
'runworkercompletedhandler'
//here utilize e.result create output message messagebox is there easier way show messagebox within past eventhandler?
you can add together work item onto ui thread work item queue using dispatcher class. seek this:
public void dataobjectpastingeventhandler(object sender, dataobjectpastingeventargs e) { dispatcher.currentdispatcher.invoke((action)delegate() { messagebox.show("hello"); }); } update >>>
there couple of things can try... first initialise dispatcher on ui thread. phone call in window constructor or in loaded event handler, can sure ui thread running:
dispatcher uidispatcher = dispatcher.currentdispatcher; if doesn't prepare problem, can seek run original method asynchronously:
public void dataobjectpastingeventhandler(object sender, dataobjectpastingeventargs e) { dispatcher.begininvoke((action)delegate() { messagebox.show("hello"); }, null); } if that still doesn't work, i'm out of ideas... find somewhere else launch messagebox from.
c# wpf event-handling
Comments
Post a Comment