如何在C#中以编程方式更改WPF文本框的背景和前景色?
textBox1.Background = Brushes.Blue; textBox1.Foreground = Brushes.Yellow;
WPF前景和背景类型System.Windows.Media.Brush。您可以像这样设置其他颜色:
System.Windows.Media.Brush
using System.Windows.Media; textBox1.Background = Brushes.White; textBox1.Background = new SolidColorBrush(Colors.White); textBox1.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0, 0)); textBox1.Background = System.Windows.SystemColors.MenuHighlightBrush;