Reputation: 17
How do i make focus disappear on:
<Textbox Name="Textbox1" />
Or, if i can't make focus go away where is it before anything is focused ?
Upvotes: 0
Views: 291
Reputation: 46595
You can use FocusManager to set focus to something else. I'm not sure when you want to change the focus or where in your code you want to make the call from, but I put a call to FocusManager in the code behind of a form and set its focus to itself and it seems to work fine.
e.g. if you add this to your KeyUp event your textbox will lose focus when you press a
private void TextBox_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.A)
FocusManager.SetFocusedElement(this, this);
}
Upvotes: 0
Reputation: 5614
You can use SetFocusedElement property to set focus to some other control.
http://msdn.microsoft.com/en-us/library/aa969768.aspx
Also check out FocusManager.SetIsFocusScope Method http://msdn.microsoft.com/en-us/library/system.windows.input.focusmanager.setisfocusscope.aspx
Upvotes: 0
Reputation: 1705
Did you try setting IsTabStop=False and Focusable=false?
you can check this also:
http://msdn.microsoft.com/en-us/library/aa969768.aspx
Upvotes: 1
Reputation: 6088
You could change the focus with the GotFocus (http://msdn.microsoft.com/en-us/library/system.windows.forms.control.gotfocus.aspx) Event of the textbox
Upvotes: 0