Para utilizar ese HighlightingRule
, que habría que crear otra instancia del motor de resaltado (HighlightingColorizer
etc.)
Es más fácil y más eficiente para escribir una DocumentColorizingTransformer
que pone de relieve su palabra:
public class ColorizeAvalonEdit : DocumentColorizingTransformer
{
protected override void ColorizeLine(DocumentLine line)
{
int lineStartOffset = line.Offset;
string text = CurrentContext.Document.GetText(line);
int start = 0;
int index;
while ((index = text.IndexOf("AvalonEdit", start)) >= 0) {
base.ChangeLinePart(
lineStartOffset + index, // startOffset
lineStartOffset + index + 10, // endOffset
(VisualLineElement element) => {
// This lambda gets called once for every VisualLineElement
// between the specified offsets.
Typeface tf = element.TextRunProperties.Typeface;
// Replace the typeface with a modified version of
// the same typeface
element.TextRunProperties.SetTypeface(new Typeface(
tf.FontFamily,
FontStyles.Italic,
FontWeights.Bold,
tf.Stretch
));
});
start = index + 1; // search for next occurrence
}
}
}
* ¡Muchas gracias! * –
No veo cómo responde esto a la pregunta. El usuario quería un comportamiento donde todas las palabras se destaquen en un texto si coinciden. Algo similar como el estudio visual. – Devid