Converting system.windows.media.brush to Hex color code

喜夏-厌秋 提交于 2019-12-12 11:11:18

问题


In my Windows phone7 application I placed a canvas and have set its background color to some hex color code.Now I am not able get the hex color code value through c# code.I used the below code but it give the color value in system.windows.media.brush.Plz help me with an answer?

clr = Convert.ToString(clr1.Background);

回答1:


It seems it returns a Brush and since you've set a color it should return a SolidColorBrush. Try this

var color = ((SolidColorBrush)clr1.Background).Color.ToString();

Example:

var color = new Color() {R = 0xF0, G = 0x10, B = 0x80};
var brush = new SolidColorBrush(color);
var hexcolor = brush.Color.ToString();

hexcolor equals "#00F01080"



来源:https://stackoverflow.com/questions/12160141/converting-system-windows-media-brush-to-hex-color-code

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