c# - Changing TextBox colour in a method -


i've got mvvm c# project has button on form processing. takes few seconds processing , thats fine. there associated textbox want change background colour of during processing. i've been trying no success.

i have background colour textbox bound property change @ beginning of method called button (via command binding). method work, , sets background colour default colour. no change occurs on screen when button clicked.

i've tried putting color change code inside dispatcher happen on gui thread, still doesn't work.

i'm confused. how colour change properly?

    private void switchruns()     {         try         {              // bound property (set notification correctly)             //             curruntextboxcolor = colors.red;              uiservices.setbusystate(true); // sets cursor wait              ...             processing code             ...              curruntextboxcolor = colors.lightgreen;          }         catch (exception exp)         {             log.error("exception in switchruns" + exp);         }     } 

what believe happening switchruns method called directly ui thread , therefore ui thread busy. pushing operation background thread should solve issue:

private void switchruns() {     threadpool.queueuserworkitem((o) => this.switchruns()); }  private void switchrunsasync() {     // bound property (set notification correctly)     //     this.dispatcher.begininvoke((action)(() =>     {         curruntextboxcolor = brushes.red;     }), dispatcherpriority.send);      // place load logic here in place of sleep.     thread.sleep(2000);      this.dispatcher.begininvoke((action)(() =>     {         curruntextboxcolor = brushes.lightgreen;     }), dispatcherpriority.send); } 

please note have changed curruntextboxcolor property brush , not color in order binding background property of textbox work.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -