xamlwindows-phone

Image inline with text in XAML


How do I place an image inside a text paragraph, so that the image is inline with text in XAML?

Here's an HTML equivalent of what I want to achieve:

<p>Your collection of things does not contain any items. Add a new 
item by pressing <img src="add.png"> button and choosing the 
options that you like lorem ipsum etc.</p>

I could put a TextBlock and an Image inside of a Grid and position the Image using margins, but this is very fragile, because the image would have to be repositioned manually every time text size, text length or width of the container changes. It would be better to have the image flow with the text, like in the HTML example above.


Solution

  • You should use RichTextBox to put images inline with a text

    <RichTextBox>
        <Paragraph>
            Displaying text with inline image
            <InlineUIContainer>
                <Image Source="add.png" Height="50" Width="50" />
            </InlineUIContainer>            
        </Paragraph>
    </RichTextBox>