AvalonEdit:TextEditor是否具有快速搜索/替换功能?

Fra*_*k59 12 c# search avalonedit

我用AvalonEdit:TextEditor.我可以为此控件启用快速搜索对话框(例如在Ctrl-F上)吗?或者也许有人将搜索词的代码转换为 AvalonEdit:TextEditor文本?

Ste*_*iel 23

关于它的文档不多,但AvalonEdit确实有一个内置的SearchPanel类,听起来与你想要的完全一样.甚至还有一个SearchInputHandler类使得它连接到编辑器,响应键盘快捷键等变得微不足道.以下是一些将标准搜索逻辑附加到编辑器的示例代码:

myEditor.TextArea.DefaultInputHandler.NestedInputHandlers.Add(new SearchInputHandler(myEditor.TextArea));
Run Code Online (Sandbox Code Playgroud)

下面是它的外观截图(这是从使用AvalonEdit的ILSpy中获取的).您可以在右上角看到搜索控件,它支持的搜索选项以及自动突出显示匹配结果.

使用SearchPanel在ILSpy中搜索

没有任何支持替换......但如果你只是需要搜索,这可能是一个很好的解决方案.


Joh*_*ers 15

对于Avalon Edit Version 5.0.1.0,只需执行以下操作:

SearchPanel.Install(XTBAvalonEditor);
Run Code Online (Sandbox Code Playgroud)

其中XTBAvalonEditor是WPF AvalonEdit控件名称.

确保使用以下语句添加:

using ICSharpCode.AvalonEdit.Search;
Run Code Online (Sandbox Code Playgroud)

然后当编辑器有焦点时,按CTL-F:你会在右上角看到查找控件.

在此输入图像描述


Pal*_*sen 10

在ICSharpCode.AvalonEdit项目的TextEditor构造函数中,添加SearchPanel.Install(this.TextArea); 瞧,使用ctrl + f打开搜索窗口.

(使用Stephen McDaniel的帖子中的一行(用此替换myEditor)也可以,但是对SearchInputHandler的支持正在被删除)

(适用于带有MVVM的AvalonDock内的AvalonEdit)

从:

public TextEditor() : this(new TextArea())
{
}
Run Code Online (Sandbox Code Playgroud)

至:

public TextEditor() : this(new TextArea())
{
  SearchPanel.Install(this.TextArea);
}
Run Code Online (Sandbox Code Playgroud)