autocompletebox focus in wpf

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

    You could also use a extension method for this:

    public static void ForceFocus(this AutoCompleteBox box)
    {
        if (box.Template.FindName("Text", box) is TextBox textbox)
        {
            textbox.Focus();
        }
    }
    

提交回复
热议问题