Search code examples
wpfflowdocumentreader

Setting the background color of a FlowDocument in a FlowDocumentReader


I have been using a RichTextBox to show FlowDocuments in a WPF app, but I found that there is something called FlowDocumentReaderwhich gives me alot of functionality for free. The problem is that while the background in the RichTextBox was shown as white, it is now completely transparent.

I have tried setting the Backgroundproperty, but that only changes the toolbar at the bottom.

<FlowDocumentReader Grid.Row="1" Grid.Column="1" Name="rtbShowDoc" Margin="20, 0" Background="White">
    <FlowDocumentReader.Effect>
        <DropShadowEffect BlurRadius="10" Color="Black" ShadowDepth="3" />
    </FlowDocumentReader.Effect>
</FlowDocumentReader>

Background set

I can do an ugly fix with a DockPanel, but that does not seem like the right way to do it.

<DockPanel Grid.Row="1" Grid.Column="1" Margin="20, 0" Background="White">
    <DockPanel.Effect>
        <DropShadowEffect BlurRadius="10" Color="Black" ShadowDepth="3" />
    </DockPanel.Effect>
    <FlowDocumentReader Grid.Row="1" Grid.Column="1" Name="rtbShowDoc" Background="White">
    </FlowDocumentReader>
</DockPanel>

How can I set the background of a FlowDocumentReader?

EDIT: Added screenshot of running application. As you can see the dropshadow effect is applied to all text inside the FlowDocument. Running application


Solution

  • Try setting the background of the FlowDocument

    FlowDocument.Background Property