Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a Hanging indent in either a flow document or WPF RichTextBox

Is there a way to create a hanging indent in either a flow document or a system.windows.control RichTextBox(wpf)? and if it will work in the flow document, when I load that into the RichTextBox to display it will it keep it's form?

like image 348
William Avatar asked Jan 28 '26 16:01

William


1 Answers

In the FlowDocument paragraph defentition, you can set the left margin to the hanging indent value and then set the TextIndent to the negative of that value. Below is an example:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>

    <FlowDocumentScrollViewer>
        <FlowDocument>
            <Section>
                <Paragraph TextIndent="-30" Margin="30,20,0,0">
                    The first line of this paragraph is not indented, but the rest of the lines will be indented by 30 units. The first line of this paragraph is not indented, but the rest of the lines will be indented by 30 units.
                </Paragraph>
            </Section>
        </FlowDocument>
    </FlowDocumentScrollViewer>

    <RichTextBox Grid.Row="1">
        <FlowDocument>
            <Section>
                <Paragraph TextIndent="-60" Margin="60,20,0,0">
                    The first line of this paragraph is not indented, but the rest of the lines will be indented by 60 units. The first line of this paragraph is not indented, but the rest of the lines will be indented by 60 units.
                </Paragraph>
            </Section>
        </FlowDocument>
    </RichTextBox>
</Grid>

more details on indents here WPF Documents - Indenting Paragraphs

hope this helps, regards

like image 140
serge_gubenko Avatar answered Jan 31 '26 04:01

serge_gubenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!