First things first, credit where it’s due: the StackOverflow link I eventually found that enabled me to solve this problem:
The trick is not use use a TextBlock as conventional wisdom would indicate, but to use a FlowDocument to achieve this kind of layout.
For future reference (I am going to need something like this fairly soon), try the following XAML snippet and the resulting WPF app screenshot to demonstrate how to display a button in the top right hand corner with text wrapped around it. In my real-world apps I am using the MVVM pattern with all sorts of bindings and events etc, but this should hopefully enable me to get there:
MainWindow.xaml
<Window x:Class="WpfApp1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" Title="MainWindow" Height="300" Width="400"> <Grid> <FlowDocumentScrollViewer> <FlowDocument> <Paragraph> <Floater Width="125" HorizontalAlignment="right" Margin="0,0,0,0" > <BlockUIContainer> <Button Content="Go!" Height="90" Width="100" /> </BlockUIContainer> </Floater> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse et diam felis. Vestibulum ac nisl mi. Etiam varius velit lobortis nibh vestibulum nec consequat velit pellentesque. Cras commodo libero placerat nulla dapibus eget porttitor ligula tempor. Donec nisl massa, congue et pretium sit amet, feugiat vel est. Nulla dapibus metus in justo pulvinar sit amet viverra lorem rhoncus. Integer placerat interdum massa et mattis. </Paragraph> </FlowDocument> </FlowDocumentScrollViewer> </Grid> </Window>
Which when run gives the following output:
Another example, this time using RichTextBox:
MainWindow.xaml
<Window x:Class="WrapText.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WrapText" mc:Ignorable="d" Title="MainWindow" Height="200" Width="320"> <Grid> <RichTextBox Margin="-3,-3,-3,-3" > <FlowDocument> <Paragraph> <Floater Margin="0,0,0,0" Padding="3" Width="60" HorizontalAlignment="Right"> <BlockUIContainer Margin="0,0,0,0"> <Button Width="50" Height="50" Content="Hello" /> </BlockUIContainer> </Floater> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus eu urna ipsum. Nullam vulputate quam dolor, eget porttitor ex sagittis vitae. Nunc auctor purus tellus, ut ultricies dolor imperdiet a. In scelerisque lacus et ex tempus, quis elementum lacus bibendum. Etiam lobortis dictum mauris. Sed elementum ornare libero, et consectetur sapien posuere vitae. Interdum et malesuada fames ac ante ipsum primis in faucibus. Praesent nec tortor sit amet dui varius consectetur. </Paragraph> </FlowDocument> </RichTextBox> </Grid> </Window>
Giving the following output: