焦点未正确进入目标用户控制

发布于 2024-10-03 07:48:46 字数 239 浏览 0 评论 0原文

我有一个用户控件,由一个文本框和两个按钮组成。
控件放置在对话框上,当我在对话框上切换时
控件,我体验到正确的行为 - 首先文本框获得焦点,
然后是一个按钮,然后是另一个按钮。
但是,当我将用户控件设置为键盘快捷键的目标时
使用“_”设置标签(例如按 alt+r 表示“_行数”)用户控件
没有获得任何焦点。尝试实施“gotkeyboardfocus”并设置
将焦点转移到那里的文本框控件,但它不起作用。

I've got a user control, consisting of a text box and two buttons.
the control is placed on a dialog box and when i tab over the dialog
controls, I experience proper behavior - first the text box is focused,
then one button, then the other.
However, when I set the user control as a target of a keyboard shortcut
set with "_" for a label (say press alt+r for "_Row count") the user control
does not receive any focus. Tried implementing "gotkeyboardfocus" and setting
the focus to the textbox control there but it doesn't work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生来就爱笑 2024-10-10 07:48:46

默认情况下,UserControl 不可聚焦,因此您必须将其打开才能使其正常工作。

<my:UserControl1 x:Name="userControl11" Focusable="True" .../>
<Label Target="userControl11">_Row count</Label>

然后,当 UserControl 收到 Focus 时,您可以将所需的 TextBox 聚焦在 UserControl 内

private void UserControl_GotFocus(object sender, RoutedEventArgs e)
{
    textBox.Focus();
}

A UserControl isn't focusable by default so you have to turn it on in order to get this to work.

<my:UserControl1 x:Name="userControl11" Focusable="True" .../>
<Label Target="userControl11">_Row count</Label>

And then you can focus the desired TextBox inside of the UserControl when it recieves Focus

private void UserControl_GotFocus(object sender, RoutedEventArgs e)
{
    textBox.Focus();
}
凉世弥音 2024-10-10 07:48:46

您好,我最近遇到了焦点问题。我所做的是从我的用户控件内部创建一个名为 SetFocus() 的方法。然后在该用户控件内,从消费者调用 .SetFocus() 后,我将焦点直接设置到我的文本框控件。

public void SetFocus()
{
this.txtCommand.Focus();
}

Hi I recently encountered focus problem. What I did is create a method called SetFocus() from inside my user control. Then inside that usercontrol I set the focus directly to my textbox control after calling .SetFocus() from consumer.

public void SetFocus()
{
this.txtCommand.Focus();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文