首页 文章

Silverlight的 . 如何将InlineUIContainer内容中的文本与RichTextBox中的外部文本对齐

提问于
浏览
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>

Example

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

在WPF中,属性BaselineAlignment = "Center" works fine .

但Silverlight看起来很幸运 .

2 回答

  • 2

    我罚款完美的方式(你可以从这里做出自定义控制):

    首先将您的对象包装到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

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

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

    PS:现在文字按你的意愿做...没有你用的FontStyle和FontSize ...

  • 0

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

相关问题