在我的 WPF 窗口中,当光标位于文本框上时,我希望文本框具有略带蓝色的背景。为此,我创建了两个简单的事件处理程序(GotFocus 和 LostFocus)。
private void textBox1_GotFocus(object sender, RoutedEventArgs e)
{
textBox1.Background = (Brush)new BrushConverter().ConvertFrom("#FFE6E6FF");
}
private void textBox1_LostFocus(object sender, RoutedEventArgs e)
{
textBox1.Background = Brushes.White;
}
有没有一种方法可以将每个文本框定向到一个事件处理程序,该事件处理程序为相应的文本框提供背景?