ivalueconverter - WPF BoolToBrushConverter with 4 values and 4 Brushes to return? -


i bind textbox`s brush property isvalid dependency property in usercontrol booltobrushconverter. isvalid need 4 states because need 4 different brushes return converter. there way using strings? instead of bool, work?

sure. can convert whatever want whatever want. need implement way how converted.

however, if number of states limited 4, suggest using enum instead of strings because makes safer regarding refactoring etc.

something should work:

internal enum state {     state1, state2, state3, state4 }  // ...  public void convert(object value, ...) {     if (value state)     {         state state = (state)value;         switch(state)         {             case state.state1:                 return mybrush1;             case state.state2:                 return mybrush2;             case state.state3:                 return mybrush3;             case state.state4:                 return mybrush4;         }     }      return defaultbrush; } 

btw: depending on scenario, might better use triggers, not possible.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -