0
这与WPF和C#有关。我的程序中有几个按钮,当他们被点击时,即使处理完一个事件,他们也会一直闪烁。例如,我所拥有的按钮中应该根据用户输入打开一个新窗口。如果用户的输入不正确,MessageBox就会这样说。一旦关闭了MessageBox,按钮就开始闪烁。如果用户输入正确,则新窗口将打开。一旦我从新窗口点击进入旧窗口,按钮开始闪烁;如果我关闭新窗口,按钮开始闪烁。按钮控件在点击并处理事件后保持闪烁状态
我试过使用this.Focus()遍及我的代码,涉及这个按钮来获得主窗口的焦点。我尝试使用e.Handled = true,但似乎没有任何阻止它。我不想通过将该属性设置为false来使按钮不可聚焦,因为我希望我的程序可以访问。
任何想法发生了什么?
下面是按钮我的XAML代码:
<Button x:Name="btnSearch" Content="Search" Background="#4a89be" Foreground="White"
MouseEnter="Button_MouseEnter" MouseLeave="Button_MouseLeave"
Click="btnSearch_Click" />
C#代码按钮(这并不一定this.Focus(),因为它没有为我工作):
private void btnSearch_Click(object sender, RoutedEventArgs e)
{
if (!String.IsNullOrEmpty(txtNumber.Text.ToString()) && txtNumber.Text.ToString().Length >= 10)
{
if (QueryWindow == null)
{
QueryWindow = new DatabaseQueryWindow();
QueryWindow.Show();
QueryWindow.Closed += new EventHandler(QueryWindow_Closed);
}
else if (QueryWindow != null && !QueryWindow.IsActive)
{
QueryWindow.Activate();
}
QueryDB();
}
else
{
MessageBox.Show("Please enter a valid # (Format: YYYYmm####)");
}
}
void QueryWindow_Closed(object sender, EventArgs e)
{
QueryWindow = null;
}
private void Button_MouseEnter(object sender, MouseEventArgs e)
{
Button b = sender as Button;
if (b != null)
{
b.Foreground = Brushes.Black;
}
}
private void Button_MouseLeave(object sender, MouseEventArgs e)
{
Button b = sender as Button;
if (b != null)
{
b.Foreground = Brushes.White;
}
}
你意识到你在这里谈论的“闪烁”是Windows的默认设置,对吗?尝试去控制面板 - >区域设置 - >其他设置,然后关闭弹出窗口,并观察其他设置按钮中相同的“闪烁”。 –
@HighCore哈,你说的没错,我以为有什么东西坏了。那么,我将如何摆脱闪烁,这变得相当分散注意力。我很习惯Win8开发,这对我来说很奇怪。 –