Search code examples
wpfflowdocumentflowdocumentreader

Why text from TextBlock is not displaying?


Why the text from the following TextBlock is not displaying. How can we have it displayed above the FlowDocument?

<Window x:Class="WPF_Test.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WPF_Test"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    
    <Grid>
        <TextBlock Margin="5" Text="This text is from TextBlock"/>

        <FlowDocumentReader>
            <FlowDocument Background="GhostWhite" ColumnWidth="10000">
                <List MarkerOffset="25" MarkerStyle="Decimal" StartIndex="1">
                    <ListItem>
                        <Paragraph Margin="10">Test Paragraph</Paragraph>
                        <List MarkerStyle="UpperLatin" Margin="0" Padding="0"  >
                            <ListItem Margin="40,5,0,0">
                                <Paragraph>Test paragraph</Paragraph>
                            </ListItem>
                            <ListItem Margin="40,5,0,0">
                                <Paragraph>Test paragraph</Paragraph>
                            </ListItem>
                            <ListItem Margin="40,5,0,0">
                                <Paragraph>Test paragraph</Paragraph>
                            </ListItem>
                        </List>
                    </ListItem>
                    <ListItem>
                        <Paragraph Margin="10">Test paragraph</Paragraph>
                    </ListItem>
                    <ListItem>
                        <Paragraph Margin="10">Test paragraph</Paragraph>
                    </ListItem>
                </List>
            </FlowDocument>
        </FlowDocumentReader>
    </Grid>
</Window>

MainWindow Display:

enter image description here


Solution

  • Grid adds elements based on a row and column index. The child elements TextBox and FlowDocumentReader should be located in different column/row of the grid panel:

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
    
        <TextBlock Grid.Row="0" Margin="5" Text="This text is from TextBlock"/>
    
        <FlowDocumentReader Grid.Row="1">
        ....    
    </Grid>