Embedding UIElements

The fact that RichTextBlock can contain embedded UIElements is not obvious from looking at its APIs. This capability comes from the InlineUIContainer element, which is an Inline. It has a simple Child content property of type UIElement.

Although InlineUIContainer should be able to be added to the plain old TextBlock’s Inlines collection, doing so fails at runtime. It turns out that InlineUIContainers must be placed within a Block, and this is the reason that this feature is supported only by RichTextBlock.

The capability to embed a UIElement among text means you can insert just about anything: an image, a video, a Panel containing a large tree of elements, and so on. Such elements are fully interactive and can get focus, ...

Get Universal Windows® Apps with XAML and C# Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.