我有一个可编辑的WPF组合框。每当它获得焦点时,我希望将插入符号位置设置在文本的末尾。
GotFocus事件
上执行以下操作:TextBox textBox = this.combo.ChildrenOfType <TextBox>().
FirstOrDefault(element => element.Name == "PART_EditableTextBox");
// if textbox is null then return
if (textBox == null)
{
return;
} // if textbox == null
// set the caret index of textbox
textBox.CaretIndex = textBox.Text.Length;
PART_EditableTextBox
是可编辑ComboBox
中提供编辑的TextBox
的名称。