如何在 C# 中以编程方式更改 WPF 文本框的背景和前景色?
textBox1.Background = Brushes.Blue; textBox1.Foreground = Brushes.Yellow;
WPF Foreground and Background 是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;