WPF 给控件设置渐变背景色

代码:

RadialGradientBrush rgbrush = new RadialGradientBrush();
rgbrush.RadiusX = 0.5;
rgbrush.RadiusY = 1;
rgbrush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF4682D6"), 0.45));
rgbrush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF3867CC"), 0.87));
Control.Background = rgbrush;

Xaml:


    
        
        
    

效果如下图:


Screen Shot 2021-07-15 at 10.15.54.png

你可能感兴趣的:(WPF 给控件设置渐变背景色)