我在写我的工程作品。我对Avalon Edit控件有问题。我想添加一些文本的按钮点击在光标位置。但是我做不到,我已经试过所有我找到的东西了。我从avalonEdit那里连CaretOffset都弄不到。
<avalonEdit:TextEditor
Document="{Binding Dokument, UpdateSourceTrigger=PropertyChanged}"
IsModified="{Binding Path=Edited, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsReadOnly="{Binding ReadOnly}"
ShowLineNumbers="True"
SyntaxHighlighting="XML"
>如何以其他方式将文本粘贴到光标位置?非常感谢您的帮助或提示;-)
发布于 2018-01-09 08:01:30
可能是错的;都是未经测试的。
我认为您需要访问您的TextDocument实例。根据GitHub上的代码,应该有一个Insert(int offset, string text)方法:https://github.com/icsharpcode/AvalonEdit/blob/master/ICSharpCode.AvalonEdit/Document/TextDocument.cs
为了获得偏移量,您需要访问TextEditor实例。在那里,您将找到CaretOffset属性。这应该会告诉您插入符号的位置,以及您传递给Insert方法的内容。https://github.com/icsharpcode/AvalonEdit/blob/master/ICSharpCode.AvalonEdit/TextEditor.cs
我会给出一个例子并对其进行测试,但我不再有权访问该代码并离开工作岗位。希望这能有所帮助。
发布于 2018-01-09 17:14:29
您需要使用编辑器实例的Document属性和它的Insert方法。
public void Insert(int startIdx, string text)
{
_avalonTextEditor.Document.Insert(startIdx, text);
}https://stackoverflow.com/questions/48159156
复制相似问题