Quantcast
Channel: SharpDevelop Community
Viewing all articles
Browse latest Browse all 1764

custom word Highlight on avalonEdit

$
0
0

Hi!

i want to customize Avalon Edit component, more specifically i want to highlight (maybe with red foreground) a word i write in a textBox..

i tried to use this class i found in documentation: (AvalonEdit_4.3.1_Source/AvalonEdit.Sample/rendering.html)

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
}   }   }

but i can't get it works :(
major problem is when i call this method CurrentContext is null. i tried to valorize it but it still doesn't working.
can you give me a hint how to use this class or another way to solve my problem?
thank you very much!

Viewing all articles
Browse latest Browse all 1764

Trending Articles