编辑文本框时默认选择的文本

本文关键字:文本 选择 默认 编辑 | 更新日期: 2023-09-27 18:05:04

基本上,我试图设置我的编辑模式的行为,在进入编辑模式时选择包含的文本。我正在尝试编辑TreeView.Item的属性Name

我的研究表明,我应该使用像TextBlock.Focus()TextBlock.SelectAll(),但我不知道我怎么能做到这一点,因为我使用这种方法我的编辑模式:

http://www.codeproject.com/Articles/72544/Editable-Text-Block-in-WPF?msg=5098686 xx5098686xx

任何想法?

编辑文本框时默认选择的文本

添加SelectAll(),如下所示:

public EditableTextBlockAdorner(EditableTextBlock adornedElement)
    : base(adornedElement)
{
    _collection = new VisualCollection(this);
    _textBox = new TextBox();
    _textBlock = adornedElement;
    Binding binding = new Binding("Text") {Source = adornedElement};
    _textBox.SetBinding(TextBox.TextProperty, binding);
    _textBox.SelectAll();
    _textBox.AcceptsReturn = true;
    _textBox.MaxLength = adornedElement.MaxLength;
    _textBox.KeyUp += _textBox_KeyUp;
    _collection.Add(_textBox);
}