I have tabControl in the form. In one of the tabItems I have textbox(myTextBox). Let's call it tabItem1. When I write something into the this text box placed in the tabItem1 I want to focus textbox(searchTextBox) in the tabItem2. I placed this code in the KeyDown of the
tabItem2.Focus();
searchTextBox.Text = searchTextBoxTeropatik.Text;
searchTextBox.Focus();
I wrote this small function for this purpose. But there is a big problem.
I press the Key
tabItem2 gets the focus.
But searchTextBox does not get the focus.(My problem)
An element can be turned into a focus scope in Extensible Application Markup Language (XAML) by setting the FocusManager attached property IsFocusScope to true . In code, an element can be turned into a focus scope by calling SetIsFocusScope.
The WPF TabControl allows you to split your interface up into different areas, each accessible by clicking on the tab header, usually positioned at the top of the control. Tab controls are commonly used in Windows applications and even within Windows' own interfaces, like the properties dialog for files/folders etc.
Call UpdateLayout()
after focusing the second TabItem
so the system gets the time to redraw the tab.
tabItem2.Focus();
UpdateLayout();
searchTextBox.Focus();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With