Question

I've added a LineTransformerClass that is derived from DocumentColorizingTransformer to the TextEditor:

TxtEditCodeViewer.TextArea.TextView.LineTransformers.Add(new ColorizeAvalonEdit());

Is there any programmatic way of invoking invalidation on the Linetransformer?

I've readily assumed that since it is added to the textview, the following should work:

TxtEditCodeViewer.TextArea.TextView.InvalidateVisual();
TxtEditCodeViewer.TextArea.TextView.InvalidateArrange();
TxtEditCodeViewer.TextArea.TextView.InvalidateMeasure();

But they don't. Just in case, I've tried the following as well:

//TxtEditCodeViewer.TextArea.TextView.InvalidateVisual();
//TxtEditCodeViewer.TextArea.TextView.InvalidateArrange();
//TxtEditCodeViewer.TextArea.TextView.InvalidateMeasure();
//TxtEditCodeViewer.InvalidateVisual();
//TxtEditCodeViewer.InvalidateArrange();
//TxtEditCodeViewer.InvalidateMeasure();
//TxtEditCodeViewer.TextArea.InvalidateArrange();
//TxtEditCodeViewer.TextArea.InvalidateMeasure();
//TxtEditCodeViewer.TextArea.InvalidateVisual();
Was it helpful?

Solution

The text view maintains a cache of the generated visual lines. Forcing WPF to repaint the control just makes it re-use the results in the cache and does not call your line transformer again.

You can use the TextView.Redraw method to invalidate the cached visual lines:

textEditor.TextArea.TextView.Redraw(segment); // invalidate portion of document
textEditor.TextArea.TextView.Redraw(); // invalidate whole document

This works for both ElementGenerators and LineTransformers.

For BackgroundRenderers, it is not necessary to invalidate visual lines. Instead, just tell the text view to invalidate the layer to which your background renderer belongs:

textEditor.TextArea.TextView.InvalidateLayer(this.Layer);

OTHER TIPS

I had the same problem. I set the backgroundcolor of some text...

So i had to do a Workaround, before set background (the background is saved in the cache):

if (Txtpreview.TextArea.TextView.LineTransformers.Count > 2)
{
    Txtpreview.TextArea.TextView.LineTransformers.RemoveAt(1); // removes selection highlight
}
Txtpreview.TextArea.TextView.LineTransformers.Add(new MarkSameWord(Txtpreview.SelectedText));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top