Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change background color of button in UWP Apps in c# ?

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 ?

like image 221
Ali.Ghzd Avatar asked Mar 18 '16 06:03

Ali.Ghzd


People also ask

How do I change the background color of my clicking button?

Use HTML DOM Style backgroundColor Property to change the background color after clicking the button. This property is used to set the background-color of an element.

How do I change the color of a button in WPF?

The BorderBrush property of the Button sets a brush to draw the border of a Button. You may use any brush to fill the border. The following code snippet uses a linear gradient brush to draw the border with a combination of red and blue color.

How to change the background color of a button in Visual Studio?

Using the following steps you will set the background color of your button: Step 1: Create a windows form as shown in the below image: Visual Studio -> File -> New -> Project -> WindowsFormApp Step 2: Drag the Button control from the ToolBox and drop it on the windows form. You are allowed to place ...

What is the default placeholder color in UWP applications?

In UWP applications, the default placeholder color is black, if our application textbox background color is also black then the placeholder text will have the same color, so in this article we will change the placeholder color.

How to set the backcolor property of button in Java?

Here, Color indicates the background color of the button. Following steps are used to set the BackColor property of the Button: Step 1: Create a button using the Button () constructor is provided by the Button class.

What is the use of background color property in button class?

This property is provided by Button class and helps programmers to create more good looking buttons in their forms. You can use this property in two different methods: 1. Design-Time: It is the easiest method to set the background color of the button.


1 Answers

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"];
like image 87
Damir Arh Avatar answered Sep 23 '22 02:09

Damir Arh