将system.windows.media.brush转换为十六进制颜色代码 [英] Converting system.windows.media.brush to Hex color code

查看:1991
本文介绍了将system.windows.media.brush转换为十六进制颜色代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Windows phone7应用程序,我放置了一个画布,并将其背景颜色设置为一些十六进制颜色代码。现在我不能通过c#代码获得十六进制颜色代码值。我使用以下代码,但它给出的颜色值在system.windows.media.brush.Plz帮助我一个答案?

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);


推荐答案

看起来它返回 Brush ,因为你设置了一个颜色,它应该返回一个 SolidColorBrush 。尝试此

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();

示例:

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

hexcolor equals #00F01080

这篇关于将system.windows.media.brush转换为十六进制颜色代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆