Silverlight How to align text in InlineUIContainer content with external text in RichTextBox

Objective: Make the text content of InlineUIContainer embedded in external text.

The standard behavior of InlineUIContainer content is when the bottom edge is embedded in the outer text.

You can shift the position of an InlineUIContainer with a RenderTransform, but a value of Y should be chosen for each type and font size - this is not an ideal 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>

Example

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

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

But Silverlight seems happy with that functionality.

+3
source share
2

( ):

...

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

LayoutUpdated Canvas

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

F5 :)

PS: , ... , FontStyle FontSize...

+2

Border.Margin.. ( "0, -5,0, -5" )

0

All Articles