C# wpf Brush转Hex字符串的实例代码
程序员文章站
2022-03-30 23:30:19
我就废话不多说了,大家还是直接看代码吧~//from materialdesigndemo.converters public class brushtohexconverter : ivalueco...
我就废话不多说了,大家还是直接看代码吧~
//from materialdesigndemo.converters public class brushtohexconverter : ivalueconverter { public object convert(object value, type targettype, object parameter, cultureinfo culture) { if (value == null) return null; string lowerhexstring(int i) => i.tostring("x2").tolower(); var brush = (solidcolorbrush)value; var hex = lowerhexstring(brush.color.r) + lowerhexstring(brush.color.g) + lowerhexstring(brush.color.b); return "#" + hex; } public object convertback(object value, type targettype, object parameter, cultureinfo culture) { throw new notimplementedexception(); } }
补充:c# 16进制转 brush 颜色对象
代码图如下:
代码片如下:
brushconverter brushconverter = new brushconverter(); popupborder.background = (brush)brushconverter.convertfromstring("#121212"); messagelabel.foreground = (brush)brushconverter.convertfromstring("#7d7d7d");
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。如有错误或未考虑完全的地方,望不吝赐教。
下一篇: 鱿鱼如何保鲜