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

心已入冬 提交于 2019-12-23 10:04:08

问题


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>

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


回答1:


have you tried playing around with InlineUIContainer.BaselineAlignment

here are some examples for how to use it



来源:https://stackoverflow.com/questions/5225268/wpf-how-to-align-text-in-inlineuicontainer-content-with-outer-text-in-richtextb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!