WPF中的一些常用类型转换

原文: WPF中的一些常用类型转换

1.string和Color的转换:

//string转Color
(Color)ColorConverter.ConvertFromString((string)str);
//Color转string
((Color)value).ToString();

2.string和Brush的转换:

//string转Brush 
Brush color = new SolidColorBrush((Color)ColorConverter.ConvertFromString((string)str));
//Brush转string
((Brush)value).ToString();

3.string和byte[]的转换:

//string转byte[]
System.Text.UnicodeEncoding converter = new System.Text.UnicodeEncoding();
byte[] stringBytes = converter.GetBytes(inputString);
//byte[]转string
System.Text.UnicodeEncoding converter = new System.Text.UnicodeEncoding();
string outputString = converter.GetString(stringByte);
 

猜你喜欢

转载自www.cnblogs.com/lonelyxmas/p/9589374.html