且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

autocompletebox焦点在WPF

更新时间:2023-12-06 14:04:58

我经历了同样的事情 - 它不以目前的形式正常工作(我希望你在谈论自带的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();
    }
}

这将焦点置于这是默认的部分实际文本框(称为文字)控件模板

This sets focus to the actual TextBox (called "Text") that is part of the default ControlTemplate.