如何在c#中的UWP Apps中更改按钮的背景色? [英] how to change background color of button in UWP Apps in c# ?

查看:183
本文介绍了如何在c#中的UWP Apps中更改按钮的背景色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的按钮,我需要每秒更改按钮的颜色.我使用此代码btnBlue.Background = new SolidColorBrush(Windows.UI.Colors.Blue),但是它不包含我在xaml中使用过的自定义颜色,例如#FF30B3DD! 所以我该怎么做 ?有谁能够帮我 ?

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 ?

推荐答案

您可以使用Color.FromArgb()在代码中定义自定义颜色:

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

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

或者,您可以预先在XAML中将颜色定义为资源:

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"];

这篇关于如何在c#中的UWP Apps中更改按钮的背景色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆