简体   繁体   English

如何在c#中更改UWP应用程序中按钮的背景颜色?

[英]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 ! 我使用此代码btnBlue.Background = new SolidColorBrush(Windows.UI.Colors.Blue)但它不包含我在xaml中使用的自定义颜色,如#FF30B3DD So what should I do ? 所以我该怎么做 ? can anybody help me ? 有谁能够帮我 ?

You can use Color.FromArgb() to define a custom color in code: 您可以使用Color.FromArgb()在代码中定义自定义颜色:

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

Alternatively, you can define the color in XAML in advance as a resource: 或者,您可以预先将XAML中的颜色定义为资源:

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

You can then reference the resource from the code: 然后,您可以从代码中引用资源:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM