Creating SolidColorBrush from hex color value

后端 未结 6 1511
挽巷
挽巷 2020-12-12 14:59

I want to create SolidColorBrush from Hex value such as #ffaacc. How can I do this?

On MSDN, I got :

SolidColorBrush mySolidColorBrush = new SolidCol         


        
6条回答
  •  盖世英雄少女心
    2020-12-12 15:21

    using System.Windows.Media;
    
    byte R = Convert.ToByte(color.Substring(1, 2), 16);
    byte G = Convert.ToByte(color.Substring(3, 2), 16);
    byte B = Convert.ToByte(color.Substring(5, 2), 16);
    SolidColorBrush scb = new SolidColorBrush(Color.FromRgb(R, G, B));
    //applying the brush to the background of the existing Button btn:
    btn.Background = scb;
    

提交回复
热议问题