Rene Schulte
Rene Schulte

Reputation: 2962

WP RichTextBox Vertical Alignment

I'm dynamically parsing data and adding text as Run, Hyperlinks and images as InlineUIContainer into a Windows Phone 8.0 RichTextBox. Somehow I can't manage that the images vertically align centered with the text.

Images are added like this:

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

And text like that:

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

I tried to set a few values for alignment on the RichTextBox as well, but the text is never centered with the images. The text is always bottom aligned.

Any chance getting the inline images vertically centered with the inline text in the WP RichTextBox?

Upvotes: 0

Views: 935

Answers (2)

fs_dm
fs_dm

Reputation: 401

Sorry for late reply. Try to set Margin for your Inline Images:

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

Upvotes: 1

Jarod Kientz
Jarod Kientz

Reputation: 131

I think what you are looking for is the BaselineAlignment Property. try the following :

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

Upvotes: 1

Related Questions