WP RichTextBox垂直对齐

时间:2014-04-22 18:39:15

标签: xaml windows-phone-8 richtextbox

我动态解析数据并将文本作为运行,超链接和图像作为InlineUIContainer添加到Windows Phone 8.0 RichTextBox中。不知何故,我无法管理图像垂直对齐以文本为中心。

图像添加如下:

        Paragraph paragraph = new Paragraph();
        richTextBox.Blocks.Add(paragraph);

        var img = new Image
        {
            Stretch = Stretch.Uniform,
            Source = imageSource,
            VerticalAlignment = VerticalAlignment.Center,
            Height = inlineImageSize,
        };

        paragraph.Inlines.Add(new InlineUIContainer {Child = img});

这样的文字:

        Paragraph paragraph = new Paragraph();
        richTextBox.Blocks.Add(paragraph);
        paragraph.Inlines.Add(new Run { Text = text });

我也尝试在RichTextBox上设置一些对齐值,但文本从不以图像为中心。文本始终是底部对齐的。

是否有机会使内嵌图像垂直居中于WP RichTextBox中的内嵌文本?

2 个答案:

答案 0 :(得分:1)

我认为你要找的是BaselineAlignment属性。 尝试以下方法:

Paragraph paragraph = new Paragraph();
    richTextBox.Blocks.Add(paragraph);

    var img = new Image
    {
        Stretch = Stretch.Uniform,
        Source = imageSource,
        BaselineAlignment = BaselineAlignment.Center,
        Height = inlineImageSize,
    };

    paragraph.Inlines.Add(new InlineUIContainer {Child = img});

答案 1 :(得分:1)

很抱歉迟到的回复。尝试为内嵌图像设置边距:

Paragraph paragraph = new Paragraph();
richTextBox.Blocks.Add(paragraph);

var img = new Image
{
    Stretch = Stretch.Uniform,
    Source = imageSource,
    Height = inlineImageSize,
    Margin = new Thickness(0,0,0,-5);
};

paragraph.Inlines.Add(new InlineUIContainer {Child = img});