如何防止文本块重叠?

时间:2015-12-06 09:27:29

标签: c# wpf xaml

我已经尝试过这个问题ViewBox但是对于某些分辨率,结果很奇怪,字体太大而且我想保持我的字体大小所以ViewBox不利于这个目标。这是我的结构:

<StackPanel Orientation="Vertical"  Grid.Column="0" Grid.Row="5">
          <TextBlock TextDecorations="Underline" FontWeight="Bold" HorizontalAlignment="Center">Fattore forma (casa)</TextBlock>
          <Label Content="40%" HorizontalAlignment="Center" FontWeight="Bold" FontSize="20"></Label>
</StackPanel>

<StackPanel Orientation="Vertical" Grid.Column="1" Grid.Row="5" Margin="5,0">
           <TextBlock TextDecorations="Underline" FontWeight="Bold" HorizontalAlignment="Center">Fattore forma (fuori)</TextBlock>
           <Label Content="35%" HorizontalAlignment="Center" FontWeight="Bold" FontSize="20"></Label>
</StackPanel>

<StackPanel Orientation="Vertical" Grid.Column="2" Grid.Row="5">
           <TextBlock TextDecorations="Underline" FontWeight="Bold" HorizontalAlignment="Center">Totali giocate</TextBlock>
           <Label Content="9" HorizontalAlignment="Center" FontWeight="Bold" FontSize="20"></Label>
</StackPanel>

现在主要的问题是,如果我将窗口调整到最小分辨率,我会得到文本重叠,我想避免这种情况,这样做最好的想法是什么?我是wpf的新手,所以我实际上正在学习解决这个问题的最佳解决方案。

图片示例:

enter image description here

建议的新代码:

<Grid Grid.Column="0" Grid.Row="5" Grid.ColumnSpan="3">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="15" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>
                                <TextBlock TextDecorations="Underline" FontWeight="Bold" HorizontalAlignment="Center" Grid.Column="0" Grid.Row="0">Fattore forma (casa)</TextBlock>
                                <Label Content="40%" HorizontalAlignment="Center" FontWeight="Bold" FontSize="20" Grid.Column="0" Grid.Row="1"></Label>
                                <TextBlock TextDecorations="Underline" FontWeight="Bold" HorizontalAlignment="Center" Grid.Column="1" Grid.Row="0">Fattore forma (fuori)</TextBlock>
                                <Label Content="35%" HorizontalAlignment="Center" FontWeight="Bold" FontSize="20" Grid.Column="1" Grid.Row="1"></Label>
                                <TextBlock TextDecorations="Underline" FontWeight="Bold" HorizontalAlignment="Center" Grid.Column="2" Grid.Row="0">Totali giocate</TextBlock>
                                <Label Content="9" HorizontalAlignment="Center" FontWeight="Bold" FontSize="20" Grid.Column="2" Grid.Row="1"></Label>
                            </Grid>

1 个答案:

答案 0 :(得分:2)

似乎StackPanel位于Grid的行和列定义中,并且您没有粘贴整个代码。

但是,您可以在TextTrimming="CharacterEllipsis"中使用TextBlock。当文字太长时,它会自动添加点。

如果要将文本换行到新行,请

TextWrapping="Wrap"