【问题标题】:Editable ComboBox setting caret position using mvvm使用 mvvm 设置插入符号位置的可编辑组合框
【发布时间】:2013-05-04 17:27:13
【问题描述】:

我有一个可编辑的 wpf 组合框。我想在获得焦点时将插入符号位置设置为文本的末尾。

【问题讨论】:

  • 对不起,我不得不删除我的答案,代码适用于 TextBox,而不是 ComboBox。

标签: wpf mvvm combobox caret cursor-position


【解决方案1】:

你可以在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 中的编辑。

【讨论】:

  • 谢谢。但我想知道是否有任何方法可以通过视图模型中的 mvvm(即)来做到这一点。
  • 这基本上是视图的一部分。最好只在 View 端处理视图内容
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-07-24
  • 1970-01-01
  • 2014-03-10
  • 1970-01-01
  • 2011-04-27
  • 1970-01-01
  • 2015-06-13
相关资源
最近更新 更多