autocompletebox focus in wpf

前端 未结 7 1738
無奈伤痛
無奈伤痛 2020-12-20 15:57

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 t

7条回答
  •  粉色の甜心
    2020-12-20 16:28

    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).

    I created a subclass:

    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.

提交回复
热议问题