Why doesn't setting the Foreground property of a RichEditBox to a LinearGradientBrush do anything?

115 views Asked by At

I'm trying to set the foreground of a WinRT XAML RichEditBox to a linear gradient so that the text appears to fade to transparency at the top and bottom edges of the element. I've specified the LinearGradientBrush as follows:

<LinearGradientBrush x:Key="ForegroundColor" StartPoint="0.5,0" EndPoint="0.5,1">
    <GradientStop Color="#00424242" Offset="0.0"/>
    <GradientStop Color="#FF424242" Offset="0.1"/>
    <GradientStop Color="#FF424242" Offset="0.9"/>
    <GradientStop Color="#00424242" Offset="1.0"/>
</LinearGradientBrush>

For some reason, this doesn't do anything to the text. Even when I remove the opacity and change the color values to different primary colors, there is no change to the color of the text. The gradient should be specified correctly, because I can change the background of the RichEditBox to it and it displays as would be expected. The documentation appears to suggest that this should be possible, but I can't seem to make it do anything at all to the foreground/text.

What am I doing wrong? How can I achieve what I'm trying to do?

1

There are 1 answers

1
user3449857 On

There is RichTextBox.Document property which contains your text. You should use FlowDocument.Foreground to change text brush. But if document contains element which changes brush of child elements, it will override your default brush (FlowDocument.Foreground). For this case you can go through whole document recursively, find these elements and remove them or change their brush to default.