How to add a focus to an editable ComboBox in WPF

后端 未结 4 2034
离开以前
离开以前 2021-01-12 08:17

I am using an editable ComboBox in wpf but when i try to set focus from C# code, it is only shows selection. but i want to go for edit option (cursor should display for user

4条回答
  •  太阳男子
    2021-01-12 08:23

    You can try this code:

            var textBox = (comboBox.Template.FindName("PART_EditableTextBox", comboBox) as TextBox);
            if (textBox != null)
            {
                textBox.Focus();
                textBox.SelectionStart = textBox.Text.Length;
            }
    

提交回复
热议问题