Reputation: 155
I need a special underline style for a rich textbox. The line/underline can have a different color than the text above it. The line should also have a shape that I haven't seen anywhere else.
Is it possible to implement this by leveraging some functionality, ideally inheriting from a rich text control?
I'm not sure how this can be done relatively easily so any hint is much appreciated. The only way I can think of is to implement it completely from scratch. E.g., using Graphics.DrawString, etc. Which would be awful lot of work.
I've also checked third-party controls like DevExpress, Telerik, Infragistics, ComponentOne, etc. But none of them seem to support this.
Upvotes: 0
Views: 105
Reputation: 20770
The WPF RichTextBox
control serves for editing FlowDocument
instances, whose content is defined with the types from the System.Windows.Documents
namespace.
Every Inline
has a TextDecorations
property. It is a list of additional decorations (generally, in the form of lines) that are added to the text of the inline. Each of them is an instance of the TextDecoration
class.
Each TextDecoration
gets its individual Pen
, so the colour is independent from the text color. The following example creates a text comprising green letters, a purple underline and an orange overline:
<Run Foreground="Green" Text="Hello, World!" FontSize="36">
<Run.TextDecorations>
<TextDecoration Location="Underline">
<TextDecoration.Pen>
<Pen Brush="Purple"/>
</TextDecoration.Pen>
</TextDecoration>
<TextDecoration Location="OverLine">
<TextDecoration.Pen>
<Pen Brush="Orange"/>
</TextDecoration.Pen>
</TextDecoration>
</Run.TextDecorations>
</Run>
Once you're there, you can supply a brush that does not completely fill the area, but rather draws shapes, such as a VisualBrush
, to create any pattern you want.
Upvotes: 1