WPF设置背景色为渐变

1.XAML文件设置


    
    
        
            
            
        
     
    

2.C#代码设置

Border b = new Border();
b.CornerRadius = new CornerRadius(10);
b.Margin = new Thickness(0, 4, 0, 0);
/*设置渐变背景色*/
LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush();
myLinearGradientBrush.StartPoint = new Point(0.5, 0.16);
myLinearGradientBrush.EndPoint = new Point(0.5, 1.0);
myLinearGradientBrush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 122, 255), 0.0));
myLinearGradientBrush.GradientStops.Add(new GradientStop(Color.FromRgb(14, 63, 242), 1.0));
b.Background = myLinearGradientBrush;

 

你可能感兴趣的:(wpf)