令人難以置信的真棒AvalonEdit WPF TextEditor控件似乎缺乏一個重要的功能,或者至少我不明白。 給定偏移量和長度,使用HighlightColor高亮顯示TextDocument中的該部分。很簡單,對吧?AvalonEdit WPF TextEditor(SharpDevelop):如何突出顯示特定範圍的文本?
不是。我有RTFM,關於「Syntax Highlighting」的文檔讓我更困惑。 Someone else asked the same question in the SharpDevelop forums,恐怕我無法理解赫爾格倫瓦爾德的答案。
這裏是我的嘗試,使用DocumentHighlighter類(當然它不工作):
textEditor1.Text = "1234567890";
HighlightingColor c = new HighlightingColor() { FontWeight = FontWeights.ExtraBold };
DocumentHighlighter dh = new DocumentHighlighter(textEditor1.Document, new HighlightingRuleSet());
HighlightedLine hl = dh.HighlightLine(1);
hl.Sections.Add(new HighlightedSection() { Color = c, Offset = 1, Length = 3 });
謝謝你的幫助!
不應該`endOffset` =`lineStartOffset + index +「AvalonEdit」.Length`?你在哪裏添加整個字符串的長度,而不是任意偏移量爲10. – 2016-10-22 23:36:12