简体   繁体   English

如何将控件集中在WPF中的tabItem中

[英]How to focus control in the tabItem in WPF

I have tabControl in the form. 我在表单中有tabControl。 In one of the tabItems I have textbox(myTextBox). 在其中一个tabItems中,我有文本框(myTextBox)。 Let's call it tabItem1. 我们称之为tabItem1。 When I write something into the this text box placed in the tabItem1 I want to focus textbox(searchTextBox) in the tabItem2. 当我在tabItem1中放置的这个文本框中写入内容时,我想在tabItem2中聚焦textbox(searchTextBox)。 I placed this code in the KeyDown of the 我将此代码放在了KeyDown中

        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. tabItem2获得焦点。

But searchTextBox does not get the focus.(My problem) 但是searchTextBox没有得到关注。(我的问题)

Call UpdateLayout() after focusing the second TabItem so the system gets the time to redraw the tab. 在聚焦第二个TabItem之后调用UpdateLayout() ,以便系统获得重绘选项卡的时间。

  tabItem2.Focus();
  UpdateLayout();
  searchTextBox.Focus();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM