In the last blog post we discussed how to hide text regions without using the code outlining feature in SyntaxEditor for WPF. Today I’d like to show how you can replace the collapsed text regions with an intra-text adornment.
Here is a another open source QuickStart that ships with SyntaxEditor. In the editor, I will select some text and then press the Collapse Selected Text button at the top.
Similar to our last QuickStart, the text that was selected was hidden. The difference is that here, we have reserved some space in-line with the text and rendered a custom adornment in that space. The custom adornment could be anything, even a control. For this QuickStart, we made it look like a standard collapsed text adornment.
How does it work?
As in the previous post, we are using an ICollapsedRegionTag object to “tag” the region that should be hidden. In this sample we also will tag the same text range with IIntraTextSpacerTag. The SyntaxEditor text formatting engine knows that when a collapsed region is found, it should look for an intra-text spacer with the same range. If one is found, it will use that in place of where the collapsed text would have been.
Then the final step is to make an adornment manager that inherits our IntraTextAdornmentManagerBase class. With that, it automatically finds intra-text spacer tags of the type you specify and asks you for an adornment element anytime one is found. In the case of this sample, our adornment is the gray border with the ellipses inside.
The whole model is completely extensible in many ways, and allows you to achieve some really neat effects.
Summary
In SyntaxEditor for WPF, you now have three ways you can hide text:
Some other uses for the feature demoed in this post… maybe you want to change any instance of a [ or ] character into some image that represents an open and close brace, thus providing more of a visual impact. You would simple collapse the text ranges of either of those characters and render adornments (that are the images) in their place. That sounds like another great idea for a QuickStart. Maybe we’ll add a sample like that in the future! :)