Background的值是一个Brush类型,所以我们可以设置他的值为SolidColorBrush,可以直接new一个SolidColorBrush对象给它赋值。

 

1 var foregroundColor = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#848789"));
2 var foregroundColor = new SolidColorBrush(Colors.Red);

 

然后直接给相应的对象设置

 

Border border = new Border();
border.Background = foregroundColor;

 

后台手动设置Background的值 WPF XAML C#

 

相关文章: