我使用AvalonEdit:TextEditor
。我能否爲此控件啓用快速搜索對話框(例如,在Ctrl-F上)?或者,也許有人有搜索詞的代碼到AvalonEdit:TextEditor
文本?AvalonEdit:TextEditor是否具有快速搜索/替換功能?
回答
沒有關於它的多文檔,但AvalonEdit確實有在SearchPanel類,聽起來完全像你想要的建造。甚至有一個SearchInputHandler類,它使平凡得到它掛接到你的編輯器,響應快捷鍵,等在這裏的是,連接標準的搜索邏輯編輯一些示例代碼:
myEditor.TextArea.DefaultInputHandler.NestedInputHandlers.Add(new SearchInputHandler(myEditor.TextArea));
這裏它是什麼樣子的截圖(這取自使用AvalonEdit的ILSpy)。您可以在右上角看到搜索控件,它支持的搜索選項以及自動突出顯示的匹配結果。
沒有對更換任何支持......但如果你只需要搜索,這可能是一個很好的解決方案。
我最後一次檢查它是「否」。您將不得不實現您自己的搜索/替換功能。
http://community.icsharpcode.net/forums/p/11536/31542.aspx#31542
您可以快速添加查找/從這裏更換 - http://www.codeproject.com/Articles/173509/A-Universal-WPF-Find-Replace-Dialog
ICSharpCode.AvalonEdit 4.3.1.9429
搜索和亮點項目。
private int lastUsedIndex = 0;
public void Find(string searchQuery)
{
if (string.IsNullOrEmpty(searchQuery))
{
lastUsedIndex = 0;
return;
}
string editorText = this.textEditor.Text;
if (string.IsNullOrEmpty(editorText))
{
lastUsedIndex = 0;
return;
}
if (lastUsedIndex >= searchQuery.Count())
{
lastUsedIndex = 0;
}
int nIndex = editorText.IndexOf(searchQuery, lastUsedIndex);
if (nIndex != -1)
{
var area = this.textEditor.TextArea;
this.textEditor.Select(nIndex, searchQuery.Length);
lastUsedIndex=nIndex+searchQuery.Length;
}
else
{
lastUsedIndex=0;
}
}
替換操作:
public void Replace(string s, string replacement, bool selectedonly)
{
int nIndex = -1;
if(selectedonly)
{
nIndex = textEditor.Text.IndexOf(s, this.textEditor.SelectionStart, this.textEditor.SelectionLength);
}
else
{
nIndex = textEditor.Text.IndexOf(s);
}
if (nIndex != -1)
{
this.textEditor.Document.Replace(nIndex, s.Length, replacement);
this.textEditor.Select(nIndex, replacement.Length);
}
else
{
lastSearchIndex = 0;
MessageBox.Show(Locale.ReplaceEndReached);
}
}
在ICSharpCode.AvalonEdit項目的TextEditor構造函數中,添加SearchPanel.Install(this.TextArea);瞧,使用Ctrl + F打開搜索窗口。
(使用斯蒂芬麥克丹尼爾的交行(更換此MyEditor的)也可以,但是對於SearchInputHandler的支持已經被刪除)
從(裏面AvalonDock AvalonEdit與MVVM效果很好):
public TextEditor() : this(new TextArea())
{
}
要:
public TextEditor() : this(new TextArea())
{
SearchPanel.Install(this.TextArea);
}
Avalon的編輯版本5.0.1.0,只是這樣做:
SearchPanel.Install(XTBAvalonEditor);
哪裏XTBAvalonEditor是WPF AvalonEdit控件名稱。
確保添加此using語句:
using ICSharpCode.AvalonEdit.Search;
然後當編輯器有重點,按CTL-F:你會看到查找控制在右上角彈出。
除此之外還有什麼可以做的嗎?在以這種方式「安裝」之後,當我點擊CTRL-F時顯示,但我無法輸入。 – Gimly
- 1. 快速製作Javascript搜索功能
- 2. 在Alfresco Web快速入門中是否有高級搜索功能?
- 3. 智能是否具有字符串替換功能?
- 4. Xlib的圖形功能是否快速?
- 5. 快速搜索
- 6. cscope是否具有搜索歷史記錄或搜索查詢堆棧功能?
- 7. 是否有快速替代棄用`SKPaymentTransaction.transactionReceipt`?
- 8. 快速查詢不搜索,搜索速度慢,但在SSMS中快速搜索
- 9. 功能是否快?
- 10. Magento快速搜索
- 11. Android快速搜索
- 12. 在C++中是否有「float」的快速fabsf替換?
- 13. 快速搜索和MS Word中樣式的替換
- 14. 快速搜索和替換正則表達式
- 15. 具有搜索功能的TreeModelAdapter
- 16. Android 2.2 AVD:否快速搜索框?
- 17. MySQL全文搜索:需要快速插入和快速搜索
- 18. 可靠和有效的定製搜索和替換功能 - preg或str替換
- 19. KML是否支持搜索功能
- 20. 在android中創建一個快速文件搜索功能
- 21. Xcode的快速搜索功能在哪裏?
- 22. 爲快速搜索記錄添加篩選功能
- 23. 如何實現帶編輯文本的快速搜索功能
- 24. 與快速搜索搜索插件
- 25. 快速onkeyup功能
- 26. maven是否有可能不在搜索版本庫中搜索快照?
- 27. 替換使用具有替換功能的正則表達式
- 28. 搜索具有相似功能的功能
- 29. 有沒有快速註釋某個功能的工具?
- 30. 一套具有複合值和快速搜索價值元素
而對於XAML?這不可能? –
當談到AvalonEdit時,我希望在XAML中使用很多很容易的東西。我通常最終從'TextEditor'繼承來擴展它。在我的一個項目中,我認爲我甚至稱它爲'BindableTextEditor',因爲我添加的所有內容都是鉤子,以便於綁定。我不是XAML專家,所以也許有更好的方法來做到這一點(行爲?),但如果你想通過XAML來控制這一點,那麼這就是我要做的方向。 –
輝煌!謝謝! – peter70