【问题标题】:Invoke search in Avalon Editor using Button click使用按钮单击在 Avalon Editor 中调用搜索
【发布时间】:2018-01-05 09:07:26
【问题描述】:

我在窗口对话框 (WPF) 中使用 AvalonEditor。窗口对话框宿主 TextEditor 控件。我在窗口上有明确的查找按钮。单击按钮后,搜索应该在 TextEditor 中工作。您能否建议如何绑定 Button Find 以调用 TextEditor Search。

目前,我已经编辑了 TextEditor 构造函数来安装 SearchPanel。当在 TextEditor 中按下 Ctrl + F 时,会出现默认搜索对话框。 我希望在 Button click 上也能做同样的事情,但使用 MVVM 方法。

请提出建议。

WPF XAML 代码

<Window>
<StackPanel Grid.Row="0" Grid.Column="1"  Orientation="Horizontal" HorizontalAlignment="Left">
            <Button Name="FindButton" Content="Find" Margin="2" Style="{DynamicResource ButtonFooter_Style}" >
                <Button.CommandBindings>
                    <CommandBinding Command="ApplicationCommands.Find" CanExecute="CommandBinding_CanExecute">
                    </CommandBinding>
                </Button.CommandBindings>
            </Button>            
        <avalonEdit:TextEditor Grid.Row="2" Grid.Column="1" Name="textEditor"
                FontFamily="Consolas"
                FontSize="10pt"                                
                SyntaxHighlighting="XML" ShowLineNumbers="True" >
        </avalonEdit:TextEditor>
</Window>

TextEditor.cs 类构造函数已经被编辑

public TextEditor() : this(new TextArea())
    {
        Search.SearchPanel.Install(this.TextArea);
    }

在按下 Ctrl + F 时启用查找功能

现在我希望查找按钮在不按 Ctrl + F 的情况下调用搜索功能。

-谢谢

【问题讨论】:

  • 向我们展示代码。根据文档,有一些命令可用于绑定到您的按钮。
  • 嗨,我添加了代码。

标签: c# wpf avalonedit


【解决方案1】:

在后面的代码中...

创建一个成员:

private readonly SearchPanel searchPanel;

在您的构造函数中,或在任何适合您需要的块中(只需要发生一次):

searchPanel = SearchPanel.Install(textEditor);

然后在事件处理代码中:

        searchPanel.SearchPattern = "eg. your selected text";
        searchPanel.Open();
        searchPanel.Reactivate();;

【讨论】:

    猜你喜欢
    • 2021-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-06
    • 2013-07-27
    • 2018-08-18
    • 2017-09-05
    相关资源
    最近更新 更多