Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF. How to align text in InlineUIContainer content with outer text in RichTextBox

The task: Make the text content of the InlineUIContainer to be inline with the outer text

The standard behaviour of the InlineUIContainer content is when the bottom edge is inline with the outer text.

It is possible to shift the content of InlineUIContainer with RenderTransform, but the value of Y has to be chosen for each font type and size - not a perfect way.

<RichTextBox>
    <FlowDocument>
        <Paragraph>
            LLL
            <InlineUIContainer>
                <Border Background="LightGoldenrodYellow">
                    <TextBlock Text="LLL"/>
                </Border>
            </InlineUIContainer>
            LLL
        </Paragraph>

        <Paragraph>
            LLL
            <InlineUIContainer>
                <Border Background="LightGoldenrodYellow">

                    <Border.RenderTransform>
                        <TranslateTransform Y="5" />
                    </Border.RenderTransform>

                    <TextBlock Text="LLL"/>

                </Border>    
            </InlineUIContainer>
            LLL
        </Paragraph>
    </FlowDocument>
</RichTextBox>

Example

How to align the text in the InlineUIContainer content with the outer text in RichTextBox regardless of font type and size?

like image 423
Vadim Loboda Avatar asked Mar 07 '11 21:03

Vadim Loboda


1 Answers

have you tried playing around with InlineUIContainer.BaselineAlignment

here are some examples for how to use it

like image 93
Markus Hütter Avatar answered Nov 02 '22 00:11

Markus Hütter