本文介绍了WPF TextBlock Textwrapping 导致文本被剪切的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 WPF TextBlock,它导致文本被剪切.生成的文本长度为 2 到 3 行.有时第一行的底部会被剪掉.

I have a WPF TextBlock which is causing the text to be clipped. The resulting text is 2 to 3 lines long. Sometimes the bottom of the first line is clipped.

以下是 XAML.问题出在 TextBlock 上:

Following is the XAML. The problem is with the TextBlock:

<Grid x:Name="background">
<Grid.ColumnDefinitions>
    <ColumnDefinition Width="Auto" />
    <ColumnDefinition />
    <ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Rectangle Width="24"
    Height="24"
    Margin="10,5"
    Fill="{StaticResource ExclaimationIcon}" />
<TextBlock Grid.Column="1"
    Margin="5"
    VerticalAlignment="Center"
    Text="{Binding Message}"
    TextWrapping="Wrap" />
<Button Grid.Column="2"
    Margin="5"
    VerticalAlignment="Top"
    Command="{Binding Clear}"
    Padding="3"
    Style="{StaticResource HiddenButtonStyle}"
    Visibility="{Binding AllowedToClear,
    Converter={StaticResource ShowOnTrue}}">
    <Image Width="12" Height="12"
        Source="/AppliancePluginLibrary;component/AdminComponents/Assets/Delete.png" />
</Button>
</Grid>

推荐答案

将 TextOption.TextFormattingMode 设置为 Display 解决了这个问题.

Setting the TextOption.TextFormattingMode to Display fixed this problem.

这篇关于WPF TextBlock Textwrapping 导致文本被剪切的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 07:04