I have a simple and I need to change colors of my buttons every second in that . I use this code btnBlue.Background = new SolidColorBrush(Windows.UI.Colors.Blue)
But it doesn't contain my custom color that I have use in xaml like #FF30B3DD
!
So what should I do ? can anybody help me ?
Asked
Active
Viewed 2.1k times
13

Ali.Ghzd
- 319
- 1
- 4
- 12
-
Possible duplicate of [In universal windows apps, how to change the background color of a button using xaml and databinding if a property in the view model changes](http://stackoverflow.com/questions/34251318/in-universal-windows-apps-how-to-change-the-background-color-of-a-button-using) – Hari Prasad Mar 18 '16 at 06:16
1 Answers
26
You can use Color.FromArgb()
to define a custom color in code:
btnBlue.Background = new SolidColorBrush(Color.FromArgb(255, 48, 179, 221));
Alternatively, you can define the color in XAML in advance as a resource:
<Page.Resources>
<SolidColorBrush x:Key="BlueColor" Color="#FF30B3DD" />
</Page.Resources>
You can then reference the resource from the code:
btnBlue.Background = (SolidColorBrush)Resources["BlueColor"];

Damir Arh
- 17,637
- 2
- 45
- 83