如何在WPF中的tabItem中集中控制 [英] How to focus control in the tabItem in WPF

查看:116
本文介绍了如何在WPF中的tabItem中集中控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表格中有tabControl。在tabItems之一中,我有textbox(myTextBox)。我们称之为tabItem1。当我向位于tabItem1中的此文本框中写入内容时,我想将焦点放在tabItem2中的textbox(searchTextBox)中。我将此代码放在

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. 我按下键

  1. I press the Key

tabItem2获取

tabItem2 gets the focus.

但是searchTextBox无法获得焦点。(我的问题)

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

推荐答案

聚焦第二个 TabItem UpdateLayout()

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

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

这篇关于如何在WPF中的tabItem中集中控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆