How to change the background color of a button in a Windows Phone application?

I am developing a Windows Phone 7 application in C # and silverlight 4. I am new to silverlight. I have two buttons in the application for different purposes. I want to dynamically change the color of a button when a button is pressed. Therefore, I use the following code

 IncomeButton.Background = new SolidColorBrush(Colors.Red);

But it does not work. Can you provide me with any code or link through which I can solve the above problem? If I am doing something wrong, then please guide me.

+3
source share
3 answers

Changing the style of a button from its own click event occurs with a trick. Here, Peter reflects.

Why can't I change the background of my button on a Click event? - Peter Torr's Blog

+4

IncomeButton.UpdateLayout() .

+2

I also ran into this "simple" problem. Instead of using the “Peter” button style change setting, I just placed a rectangle under the button and changed its color using the Rectangle.Fill property in the Click event of the button. Works great for me.

+1
source

Source: https://habr.com/ru/post/1782755/


All Articles