c#-WPF string,color,brush之间的转换

原文:c#-WPF string,color,brush之间的转换

String转换成Color

string-"ffffff"

Color color = (Color)ColorConverter.ConvertFromString(string);

String转换成Brush

BrushConverter brushConverter = new BrushConverter();
Brush brush = (Brush)brushConverter.ConvertFromString(string);

Color转换成Brush

Brush brush = new SolidColorBrush(color));

Brush转换成Color

//先将Brush转成string,再转成Color

 Color color= (Color)ColorConverter.ConvertFromString(brush.ToString());

//将Brush转成SolidColorBrush,再取Color

 Color color= ((SolidColorBrush)CadColor.Background).Color;

(ARGB)转换为Brush

Brush br = new SolidColorBrush(Color.FromArgb(cl.Color.A, cl.Color.R, cl.Color.G, cl.Color.B)); 


上一篇:【产品动态】看全域消费者运营Quick Audience如何实现自动化营销?


下一篇:修改unix服务器时间