How to focus management in tabItem ın WPF

I have a tabControl in the form. In one of the tabItems, I have a text box (myTextBox). Let me call it tabItem1. When I write something in this text box placed in tabItem1, I want to focus the text box (searchTextBox) in tabItem2. I put this code in KeyDown from

tabItem2.Focus(); searchTextBox.Text = searchTextBoxTeropatik.Text; searchTextBox.Focus(); 

I wrote this little function for this purpose. But there is a big problem.

  • I press the key

  • tabItem2 gets focus.

But searchTextBox does not get focus. (My problem)

How can I solve this problem? Thanks for attention!

+6
source share
1 answer

Call UpdateLayout() after focusing the second TabItem so that the system gets time to redraw the tab.

  tabItem2.Focus(); UpdateLayout(); searchTextBox.Focus(); 
+15
source

Source: https://habr.com/ru/post/902367/


All Articles