How to convert integer to color in WPF? For example, I want to convert 16711935 to color.
How to do something like below in windows forms, in WPF?
myControl.Background = Color.FromArgb(myColorInt);
How to convert integer to color in WPF? For example, I want to convert 16711935 to color.
How to do something like below in windows forms, in WPF?
myControl.Background = Color.FromArgb(myColorInt);
Use the BitConverter Class to convert your value to a Byte Array, that way you do not need to import another namespace.
byte[] bytes = BitConverter.GetBytes(16711935);
this.Background = new SolidColorBrush( Color.FromArgb(bytes[3],bytes[2],bytes[1],bytes[0]));
You want to use System.Drawing.Color, not System.Windows.Media.Color:
var myColor = System.Drawing.Color.FromArgb(16711935);
Ooookay, not sure this is very pretty, but you could convert from one Color class to the other, then use that in the SolidColorBrush ctor:
myControl.Background = new SolidColorBrush(
System.Windows.Media.Color.FromArgb(myColor.A,myColor.R,myColor.G,myColor.B));