autocompletebox focus in wpf

前端 未结 7 1754
無奈伤痛
無奈伤痛 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:21

    You will have to override the Focus method to find the template of the Textbox.

    public class FocusableAutoCompleteBox : AutoCompleteBox
    {
        public new void Focus()
        {
            var textbox = Template.FindName("Text", this) as TextBox;
            if (textbox != null) textbox.Focus();
        }
    }
    

提交回复
热议问题