Hi I am wanting to set the border colour of a control depending on a condition at runtime
normally you would set it with the following statement which is fixed
LGB00.BorderBrush = new SolidColorBrush(Colors.Red);
what I would like to do is set the colour depending on which condition is met ie
below is not actual code but what I want to do
string back;
if (x== 1) back = Red;
if (x == 2 back =orange
LGB00.BorderBrush = new SolidColorBrush(Colors.back); // somehow use the contents of back to set color
while on the subject of variables is it possible where I have "LGB00.BorderBrush" to us a variable that contains the string rather than the string itself so that i can be used in a loop to change multiple controls.
I'm an old machine code programmer and can do this depending on the syntax choice of imediate, relative, or contents of
( motorola 6809, 68hc11, 68hc05,) tried scoring the net but can't find answer just get plenty of error messages for my effort
cheers tony
Loading
Santhosh NPosted Dec 13, 2010, 5:53 AM
Anyway, You got it worked in anotherway and glad I could help you in pointing you in some direction which worked :)
cheers
tony turnerPosted Dec 13, 2010, 4:29 AM
thankyou for you quick reply I tried your answer without success could not get it to accept "FromName"
tried using different references in the using section.
So using the information that you supplied I found the following that done the trick.
SolidColorBrush back = new SolidColorBrush();
if (x== 1) back.Color = Colors.Orange;
if (x == 2 back.Color = Colors.Red;
LGB00.BorderBrush = back
LGB01.BorderBrush = back
etc
so thanks again for your answer as it was a big help in solving my problem
cheers
tony
Santhosh NPosted Dec 12, 2010, 8:32 AM
string back;
if (x== 1) back = "Red"; //need not worry of case either, can be "red", "Red", "REd"...
if (x == 2 back = "orange";
LGB00.BorderBrush = new SolidColorBrush(Color.FromName(back));