WPF: Setting TextBlock Height to 0 when there is no text
TextBlock
always occupies some height even if it doesn't contain any text. The height of the TextBlock
is determined by the font size if no text is present, except in case when it is explicitly set by the user, of course. Is there a way to make the TextBlock
size equal (0,0) if there is no text present (or to make it collapsed)? Thanks.
Note: I have created a converter that set's the Visibility
property of the TextBlock
to Collapsed
if there is no text, but I was wondering if开发者_如何学运维 the same or similar solution is possible without any converter or code-behind coding, i.e. to make it behave as explained only by using XAML.
<Style TargetType="TextBlock">
<Style.Triggers>
<Trigger Property="Text" Value="">
<Setter Property="Visibility" Value="Collapsed"/>
</Trigger>
</Style.Triggers>
</Style>
精彩评论