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

旧城冷巷雨未停 提交于 2019-12-22 04:21:23

问题


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 ?


回答1:


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


来源:https://stackoverflow.com/questions/36077231/how-to-change-background-color-of-button-in-uwp-apps-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!