轉自:http://www.cnblogs.com/wj-love/archive/2012/09/14/2685281.html
1,將#3C3C3C 賦給background
this.selectBook.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#3C3C3C"));
2,colordialog中的值(ARGB)轉換為Brush
Brush br = new SolidColorBrush(Color.FromArgb(cl.Color.A, cl.Color.R, cl.Color.G, cl.Color.B));
3,示例:
命名空間:
using System.Windows.Media;
1)、String轉換成Color
Color color = (Color)ColorConverter.ConvertFromString(string);
2)、String轉換成Brush
BrushConverter brushConverter = new BrushConverter();
Brush brush = (Brush)brushConverter.ConvertFromString(string);
3)、Color轉換成Brush
Brush brush = new SolidColorBrush(color));
4)、Brush轉換成Color有兩種方法:
//先將Brush轉成string,再轉成Color。 Color color= (Color)ColorConverter.ConvertFromString(brush.ToString()); //將Brush轉成SolidColorBrush,再取Color。 Color color= ((SolidColorBrush)CadColor.Background).Color;