【发布时间】:2013-05-04 17:27:13
【问题描述】:
我有一个可编辑的 wpf 组合框。我想在获得焦点时将插入符号位置设置为文本的末尾。
【问题讨论】:
-
对不起,我不得不删除我的答案,代码适用于 TextBox,而不是 ComboBox。
标签: wpf mvvm combobox caret cursor-position
我有一个可编辑的 wpf 组合框。我想在获得焦点时将插入符号位置设置为文本的末尾。
【问题讨论】:
标签: wpf mvvm combobox caret cursor-position
你可以在GotFocus event上做这样的事情:
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 基本上是TextBox 的名称,它提供可编辑的ComboBox 中的编辑。
【讨论】: