c# - 在 WPF 中将整数转换为颜色

标签 c# .net wpf colors

如何在 WPF 中将整数转换为颜色? 例如,我想将 16711935 转换为颜色。

如何在 Windows 窗体和 WPF 中执行如下操作?

myControl.Background = Color.FromArgb(myColorInt);

最佳答案

使用 BitConverter将您的值转换为字节数组的类,这样您就不需要导入另一个命名空间。

byte[] bytes = BitConverter.GetBytes(16711935);
this.Background = new SolidColorBrush( Color.FromArgb(bytes[3],bytes[2],bytes[1],bytes[0]));

关于c# - 在 WPF 中将整数转换为颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21247974/

相关文章:

c# - 如何从 DataTable 向 Excel 添加其他工作表

c# - MVVM ListView 多重绑定(bind) SelectedItems + SelectedItem (ListView) + SelectedItem (ComboBox) 到 TextBox.Text。无法正确更新

c# - 如何在文本框(WPF)中按 Control+Right 选择 2 个单词?

c# - 一些 mvvm 问题 - 知道哪个 View 当前正在编辑实体

c# - 如何将响应行为添加到 asp :GridView

c# - 如何使用 JSON.NET 序列化并忽略可空结构值

c# - 将单行从一个数据表复制到另一个

.net - 我如何知道我的程序在哪个版本的 .NET Framework 上运行?

c# - 隔离类仅由特定类 : best practices 实例化

c# - VirtualProtect-AV : Attempted to read or write protected memory