Click here to Skip to main content
15,889,879 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
This question is related to previously asked question which wasn't solved Problem when assigning Background to Button control[^]

Starting from a scratch windows phone silverlight application. I added three buttons, button1, button2, and button3. I wrote the following code in the button1_click event handler.

C#
private void button1_Click(object sender, RoutedEventArgs e)
       {

           button1.Background = new SolidColorBrush(Colors.Red);
           button2.Background = new SolidColorBrush(Colors.Brown);
           button3.Background = new SolidColorBrush(Colors.Yellow);

       }


Only button2 and button3 's background is changed, but button1's background is not altered. What can be the problem? Please help
Posted

1 solution

Problem solved!!

Instead of changing the actual background itself, using the reference of the background solves the problem.

C#
private void HighlightButton(Button btnToHighlight)
        {

            SolidColorBrush sBrush = (SolidColorBrush)btnToHighlight.Background;


            sBrush.Color = //enter your colour here
            btnToHighlight.Background = sBrush;

        }


Implemented this for all the buttons. Voila!!!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900