银光.如何将 InlineUIContainer 内容中的文本与 RichTextBox 中的外部文本对齐 [英] Silverlight. How to align text in InlineUIContainer content with outer text in RichTextBox

查看:30
本文介绍了银光.如何将 InlineUIContainer 内容中的文本与 RichTextBox 中的外部文本对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任务:使 InlineUIContainer 的文本内容与外部文本内联.

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

InlineUIContainer 内容的标准行为是当底部边缘与外部文本内联时.

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

可以使用 RenderTransform 移动 InlineUIContainer 的位置,但是必须为每种字体类型和大小选择 Y 的值 - 不是一个完美的方法.

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>

无论字体类型和大小如何,如何将 InlineUIContainer 内容中的文本与 RichTextBox 中的外部文本对齐?

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

在 WPF 中,属性 BaselineAlignment="Center" 工作正常.

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

但 Silverlight 似乎很幸运能够拥有该功能.

But Silverlight seems lucking that functionality.

推荐答案

我发现了我完美的方法(你可以从这里制作自定义控件):

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

首先将您的对象包装到 Canvas 中...

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>

并将 LayoutUpdated 事件处理程序添加到 Canvas

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);         
    }

按 F5 后你必须看到奇迹:)

After pressing F5 you have to see a miracle :)

PS:现在文本随心所欲……不管你使用什么字体样式和字体大小……

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

这篇关于银光.如何将 InlineUIContainer 内容中的文本与 RichTextBox 中的外部文本对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆