As the title suggests, my aim is to increment/decrement the font size of the current selection of text inside the RichTextBox.
This may seem trivial, and in fact it is - so long as the font size is the same for all text in the TextRange. When the selection contains text with different font sizes, the
range.GetPropertyValue(TextElement.FontSizeProperty);
which I use to get the previous value of the font size (necessary in order to know what to set the value to) returns DependencyProperty.UnsetValue .
Not only is this a problem, but also the fact that there isn't a method to increment the size, only one to explicitly set it to a given value is causing an issue here.
I've considered trying to parse the TextRange for sub ranges with different property values, but this seems like a really convoluted way to achieve something which should be trivial.
How do I go about this? Thanks in advance.
I think any implementation, if it existed, would ultimately have to do the exact same thing you propose so your options are limited:
If your concern is that this is a lot of operations, you could be right about that and the only conceptual shortcut I can think of would be to apply a ScaleTransform. This of course is only going to make it appear to work and it isn't going to change the properties of the selection.
If your concern is that this is a lot of clutter in your user code, you are also right but I'd suggest hiding that by making your own RichTextBox and implementing the IncrementSizeOfSelection and DecrementSizeOfSelection yourself.