0
我遇到过这个问题几次,还没有找到一个简单的解决方案。当一个TextBlock
(与TextWrapping="Wrap"
)嵌入另一个未指定其宽度的元素内时,TextBlock
扩展的大小与其父级允许的一样大,而不是首先尝试包装其文本。例如,我目前正在研究TextBlock
ValidationTemplate
。这里是模板目前如何处理文本比TextBox
的宽度长:防止包装TextBlock影响布局
这显然不是最佳的。这是我想它是如何出现:
下面是对于用于生产第一布局ControlTemplate
的XAML:
<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"/>
</Border>
</DockPanel>
</ControlTemplate>
有谁知道如何试图之前进行TextBlock
包扩大?