How to focus control in the tabItem in WPF

2019-04-27 01:23发布

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.

  1. I press the Key

  2. tabItem2 gets the focus.

But searchTextBox does not get the focus.(My problem)

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-04-27 01:41

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

  tabItem2.Focus();
  UpdateLayout();
  searchTextBox.Focus();
查看更多
登录 后发表回答