autocompletebox focus in wpf

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

    This is my solution for setting focus on AutoCompleteTextBox control Text:

    private void MyPageLoaded(object sender, RoutedEventArgs e) {

    var myPage = (MyControl)sender;
    var autoTextBox = (AutoCompleteTextBox)myPage.FindName("AutoTextBox");
    
    if (autoTextBox != null)
    {
        var innerTextBox = autoTextBox.textBox;
        if (innerTextBox != null)
        {
            innerTextBox.Focus();
    
        }
    }
    

    }

提交回复
热议问题