Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the background color of button on Click Event in Universal Windows Platform Apps?

I'm working on a UWP app in windows 10 and I am trying to change the background color of a button in a click event. This is my code:

private void button1_1_Click(object sender, RoutedEventArgs e)
{
    if (_Sign)
    {
        button_1_1.Content = "Cross";
        _Sign = false;
    }
    else
    {
        // button_1_1.Background = new SolidColorBrush(new Windows.UI.Color )    

        // indows.UI.Colors clr = new Windows.UI.Colors(new SolidColorBrush red);

        // SolidColorBrush color = new SolidColorBrush();
        // color = new SolidColorBrush.
        // button_1_1.Background = clr;

        button_1_1.Content = "Tick";
        _Sign = true;
    }
}
like image 638
Ammar Shaukat Avatar asked Feb 07 '23 17:02

Ammar Shaukat


2 Answers

Use the predefined color objects from the Colors properties:

button_1_1.Background = new SolidColorBrush(Windows.UI.Colors.White);
like image 109
Muhammad Bin Mustafa Avatar answered Feb 16 '23 03:02

Muhammad Bin Mustafa


You can do just that

button1.SetValue(BackgroundProperty,new SolidColorBrush(Windows.UI.Colors.Black));

You can play with that! I am not on my pc now to check it but something like that works.

or you can try

button1.Background = new SolidColorBrush(Windows.Ui.Colors.Black);
like image 28
Giorgos Neokleous Avatar answered Feb 16 '23 03:02

Giorgos Neokleous