欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C# wpf Brush轉(zhuǎn)Hex字符串的實(shí)例代碼

 更新時間:2021年01月14日 14:57:16   作者:zxcvb036  
這篇文章主要介紹了C# wpf Brush轉(zhuǎn)Hex字符串的實(shí)例代碼,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

我就廢話不多說了,大家還是直接看代碼吧~

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

補(bǔ)充:C# 16進(jìn)制轉(zhuǎn) Brush 顏色對象

代碼圖如下:

代碼片如下:

BrushConverter brushConverter = new BrushConverter();
    PopupBorder.Background = (Brush)brushConverter.ConvertFromString("#121212");
    MessageLabel.Foreground = (Brush)brushConverter.ConvertFromString("#7d7d7d");

以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。

相關(guān)文章

最新評論