1

I have a small problem with focusing in .net/wpf. I have written a custom user control which contains a TextBox and a SearchButton. The user-control has a lost focus event, which validate the content of the textbox if the focus is leaving. But now I have the problem, if I click on my search button, the lost focus event of the user control gets fired, even if I click on the button in the custom user control. (The button additionally has the option TabStop="False":

Custom-User-Control design

The problem is, that I don't want to fire the event if I click on the button.

GEOCHET
  • 21,119
  • 15
  • 74
  • 98
BendEg
  • 20,098
  • 17
  • 57
  • 131

2 Answers2

3

Set

Focusable="False"

of your search button and the TextBox will not lose the focus because the button doesn't get the focus.

gomi42
  • 2,449
  • 1
  • 14
  • 9
0

You can Do this Check in Event like this

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
}
Dgan
  • 10,077
  • 1
  • 29
  • 51