Reputation: 21138
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"
:
The problem is, that I don't want to fire the event if I click on the button.
Upvotes: 1
Views: 2066
Reputation: 2529
Set
Focusable="False"
of your search button and the TextBox will not lose the focus because the button doesn't get the focus.
Upvotes: 3
Reputation: 10295
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
}
Upvotes: 0