Of course, minutes after I post, I find the answer.
I got the idea of using a binding to enforce the width of the TextBlock
from this post.
In my case, binding the TextBlock
's width to the ActualWidth
of the AdornedElementPlaceholder
element did it:
<ControlTemplate>
<DockPanel LastChildFill="True">
<Border DockPanel.Dock="Top" BorderBrush="Red" BorderThickness="1">
<DockPanel>
<AdornedElementPlaceholder x:Name="TargetTextBox" />
<Grid x:Name="WarningBoxContainer" Background="Red" Width="{Binding ElementName=TargetTextBox, Path=ActualHeight}" Height="{Binding RelativeSource={RelativeSource Self}, Path=Width}">
<Path Margin="5" Stretch="Fill" Fill="#FFFFFFFF" Data="F1 M 26.9166,22.1667L 37.9999,33.25L 49.0832,22.1668L 53.8332,26.9168L 42.7499,38L 53.8332,49.0834L 49.0833,53.8334L 37.9999,42.75L 26.9166,53.8334L 22.1666,49.0833L 33.25,38L 22.1667,26.9167L 26.9166,22.1667 Z "/>
</Grid>
</DockPanel>
</Border>
<Border DockPanel.Dock="Top" Margin="0,2,0,0">
<TextBlock Text="Something very terrible has happened" TextWrapping="Wrap" HorizontalAlignment="Left" Width="{Binding ElementName=TargetTextBox, Path=ActualWidth}" Height="{Binding RelativeSource={RelativeSource Self}, Path=Width}"/>
</Border>
</DockPanel>
</ControlTemplate>
The end product: