RichTextBox vs FlowDocumentScrollViewer - Why Do They Look So Different?

I have a very simple xaml file where I pass the same Paragraph and Run elements for both RichTextBox and FlowDocumentScrollViewer. Both look radically different - which I did not expect.

I understand that you can create either FlowDocument or containers so that they look the same, but I expected both to inherit the same default settings.

Here is my code:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="80" />
        <RowDefinition Height="80" />
        <RowDefinition Height="80" />
    </Grid.RowDefinitions>
    <RichTextBox Grid.Row="0">
        <FlowDocument>
            <Paragraph>
                <Run>Here is some text</Run>
                <LineBreak />
                <Run>Here is some more text</Run>
            </Paragraph>
        </FlowDocument>
    </RichTextBox>
    <TextBlock Grid.Row="1" Padding="6,0,0,0">
        <Run>Here is some text</Run>
        <LineBreak />
        <Run>Here is some more text</Run>
    </TextBlock>
    <FlowDocumentScrollViewer Grid.Row="2" IsHitTestVisible="True" VerticalScrollBarVisibility="Hidden">
        <FlowDocument>
            <Paragraph>
                <Run>Here is some text</Run>
                <LineBreak />
                <Run>Here is some more text</Run>
            </Paragraph>
        </FlowDocument>
    </FlowDocumentScrollViewer>
</Grid>

My question

Is there a way to make sure that both RichTextBox and FlowDocumentScrollViewer display the FlowDocument in the same way? Ideally, you cannot tell the difference between them - without the need for a “hard code” of fields, fonts, etc. In one way or another.

, Textblock Margin, , RichTextBlock, - , , , , .

+3
1

WPF, , RichTextBox, (, ), .

FlowDocument RTB TB. ( FlowDocument - !!!)

    <RichTextBox>
        <FlowDocument Name="rtDoc"
                      PagePadding="{Binding PagePadding, ElementName=flDoc}"
                      ...
                      FontFamily="{Binding FontFamily, ElementName=flDoc}">
            ...
        </FlowDocument>
    </RichTextBox>
        ...
    <FlowDocumentScrollViewer>
        <FlowDocument Name="flDoc" />
    </FlowDocumentScrollViewer>

, !

+2

Source: https://habr.com/ru/post/1720728/


All Articles