c# - 使用 C# 更改按钮背景激活的 MainWindow
问题描述
我正在学习 c# (Visual Studio 2019)。在 MainWindow 中,我有一个带有 page1.xaml 的框架。这个page1 有几个按钮。在激活 MainWindow 时,我想将 page1 中一个按钮的背景更改为红色。我怎么能做到这一点?提前感谢您的任何回答萨宾
解决方案
您必须为按钮提供名称(例如button1),在 WPF 按钮背景中需要为 SolidColorBrush 而不是直接颜色,以便在页面加载时在 InitializeComponent() 之后的 PageFunction 中添加此代码;
SolidColorBrush brush = new SolidColorBrush(Colors.Red);// convert color to brush
button1.Backgroud=brush;// apply the brush
推荐阅读
- sql - 访问 SQL 以仅按日期返回第一次或最后一次出现
- android - android API 的领域 5.7.0 上的问题添加的部分查询不反映在 cloudRealm 上每次大多在 5 分钟后
- java - @JsonProperty 在使用 Gson 创建 JsonObject 时不会更改值
- php - 在 composer json 和 lock 文件中指定不同的版本
- matlab - 如何将地面实况数据导入 Matlab 以训练(更快)R-CNN?
- grpc - 我们可以查看/调试 GRPC 有效负载,因为它是二进制格式的吗?
- javascript - 将此对象映射到新对象的最佳方法
- sql - 如何使用加入 EXASol 删除
- jquery - 当单击的计数器上升时,当未单击的计数器再次下降时
- jquery - 在数据库中的 jquery DataTable 中显示图像