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

扶醉桌前 提交于 2020-01-02 06:57:10

问题


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 position of InlineUIContainer with RenderTransform, but the value of Y has to be chosen for each font type and size - not a perfect way.

<RichTextBox>

    <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>

</RichTextBox>

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

In WPF the property BaselineAlignment="Center" works fine.

But Silverlight seems lucking that functionality.


回答1:


I fined i perfect way around (you can make a custom control from this):

First of all wrap your object into the Canvas...

<Paragraph>LLL
<InlineUIContainer>
    <Canvas x:Name="c" LayoutUpdated="c_LayoutUpdated">
        <Border Background="LightGoldenrodYellow">
            <TextBlock x:Name="t" FontSize="32"  Text="LLL"/>
        </Border>
    </Canvas>
</InlineUIContainer> LLL
</Paragraph>

And add LayoutUpdated event handler to Canvas

    private void c_LayoutUpdated(object sender, EventArgs e)
    {
        c.Width = t.DesiredSize.Width;
        c.Height = (t.DesiredSize.Height / 1.3d);         
    }

After pressing F5 you have to see a miracle :)

PS: Now text do as you wish... no mather what FontStyle and FontSize you use...




回答2:


Try to play with Border.Margin property.. (try to set it to "0,-5,0,-5", or some other numbers)



来源:https://stackoverflow.com/questions/5242508/silverlight-how-to-align-text-in-inlineuicontainer-content-with-outer-text-in-r

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