WPF Lost-Focus问题在同一控件中

时间:2015-07-18 14:36:24

标签: c# .net wpf user-controls lost-focus

关注.net / wpf我有一个小问题。我编写了一个自定义用户控件,其中包含TextBoxSearchButton。用户控件具有丢失焦点事件,如果焦点正在离开,则会验证文本框的内容。但现在我遇到了问题,如果我单击我的搜索按钮,即使我单击自定义用户控件中的按钮,用户控件的丢失焦点事件也会被触发。 (该按钮还具有选项TabStop="False"

Custom-User-Control design

问题是,如果我点击按钮,我不想发起事件。

有人有想法吗?

谢谢!

2 个答案:

答案 0 :(得分:3)

Focusable="False"
搜索按钮的

和TextBox不会失去焦点,因为按钮无法获得焦点。

答案 1 :(得分:0)

你可以这样检查事件

protected void LostFocusEvent(object sender, RoutedEventArgs e)
{
    if(textBox.Text.Length>0)
    {
      // if there is any character in TextBox
    return;
    }

   // your validation Code goes here
}
相关问题