How to change button background color in UWP applications in C #?

I have a simple one and I need to change the colors of my buttons every second. I use this code btnBlue.Background = new SolidColorBrush(Windows.UI.Colors.Blue) But it does not contain my custom color, which I use in xaml, for example #FF30B3DD ! So what should I do? Can anybody help me?

+5
source share
1 answer

You can use Color.FromArgb() to define custom color in code:

 btnBlue.Background = new SolidColorBrush(Color.FromArgb(255, 48, 179, 221)); 

Alternatively, you can predefine the color in XAML as a resource:

 <Page.Resources> <SolidColorBrush x:Key="BlueColor" Color="#FF30B3DD" /> </Page.Resources> 

Then you can reference the resource from the code:

 btnBlue.Background = (SolidColorBrush)Resources["BlueColor"]; 
+11
source

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


All Articles