1

我使用 avalonEdit:TextEditor 来显示 XML 文件,并希望使用 ICSharpCode.AvalonEdit.Search.SearchPanel 添加搜索功能:

SearchPanel sp = new SearchPanel();
sp.Attach(textEditor.TextArea);
sp.Open();

它运行良好,但面板中的文本框没有焦点。“重新激活”方法也不起作用。谁能告诉我如何将焦点设置在 SearchPanel 中的文本框上?谢谢!

4

2 回答 2

3

Open 方法将控件插入到文本编辑器的装饰层中。你将不得不使用

sp.Dispatcher.BeginInvoke(DispatcherPriority.Input, (Action)sp.Reactivate);

在正确初始化 SearchPanel 实例触发重新激活。API 有点乱,肯定需要清理一下,但这应该可以解决你现在的问题。

于 2013-09-11T15:00:45.087 回答
0

正如 Siegfried 建议的那样,在 VB.Net 中我使用过

searchPanel.Dispatcher.BeginInvoke(Sub() searchPanel.Reactivate(), Windows.Threading.DispatcherPriority.Input)

效果很好。

于 2014-05-23T08:25:17.513 回答