3

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

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

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

<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 中的外部文本对齐?

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

但 Silverlight 似乎对这个功能很幸运。

4

2 回答 2

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:现在文字随心所欲......不管你使用什么字体样式和字体大小......

于 2011-03-09T20:29:02.623 回答
0

尝试使用Border.Margin属性..(尝试将其设置为“0,-5,0,-5”或其他一些数字)

于 2011-03-09T14:50:42.253 回答