TabItem OnSelectionChanged () setting focus internally (WPF)
I have two TabItem
contained inside a TabControl
.
Each TabItem
contains a server room TextBox
.
When the event is executed TabControl
OnSelectionChanged
, as well as the selection of a new one TabItem
, it also sets focus to the first TextBox
one contained within the newly selected element.
Is there a way to prevent this?
Setting IsTabStop="False"
to on TextBox
will do this, but unfortunately also prevents "tab" TextBox
.
In your tab control, handle the focus event for each of the tabs as follows:
<TabItem GotFocus="TabItem_OnGotFocus">
Then just remove focus using:
private void TabItem_OnGotFocus(object sender, RoutedEventArgs e)
{
Keyboard.ClearFocus();
}