wpf中的自动完成框焦点 [英] autocompletebox focus in wpf
问题描述
当我尝试专注于我的自动完成文本框"时我失败了我写了 autocompletetextbox.focus()
但是光标仍然聚焦在另一个我应该做什么或写什么才能在其中写或聚焦?
when I try to focus on my "autocompletetextbox" I failed I write autocompletetextbox.focus()
but the cursor still focus in another what should I do or write to enable to write in it or focus?
推荐答案
我遇到了同样的事情——它在当前形式下无法正常工作(我希望您在谈论 2010 年 2 月发布的 AutoCompleteBox的 WPFToolkit).
I experienced the same thing -- it does not work properly in its current form (I expect you're talking about the AutoCompleteBox that comes with the February 2010 release of WPFToolkit).
我创建了一个子类:
public class AutoCompleteFocusableBox : AutoCompleteBox
{
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
var textbox = Template.FindName("Text", this) as TextBox;
if(textbox != null) textbox.Focus();
}
}
这会将焦点设置到实际的 TextBox
(称为Text"),它是默认 ControlTemplate
的一部分.
This sets focus to the actual TextBox
(called "Text") that is part of the default ControlTemplate
.
这篇关于wpf中的自动完成框焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!