【发布时间】:2019-03-24 07:33:58
【问题描述】:
考虑下面的 WPF -
问题是出现在标签中的文本如果长于标签的宽度,则会被截断。
XAML - 标签名称是 'factTxt'
<Window x:Name="mainScreen" x:Class="FactsOnAll.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:FactsOnAll"
mc:Ignorable="d"
Title="Random Facts" Height="450" Width="800" Icon="Properties/checklist.png">
<Grid>
<Button x:Name="getFactBtn" Content="Get Random Fact" HorizontalAlignment="Left" Margin="304,331,0,0" VerticalAlignment="Top" Width="177" Click="getFactBtn_Click" FontSize="20" Background="#FF8ECF87" Foreground="#FF444444"/>
<Label x:Name="factTxt" Content="" Margin="10,98,10,0" VerticalAlignment="Top" HorizontalAlignment="Center" FontSize="20"/>
<Label x:Name="titleTxt" Content="Random Facts" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="772" Height="46" FontSize="24"/>
</Grid>
</Window>
预期结果
允许文本换行。我认为增加标签的高度可以解决这个问题,但没有运气。
【问题讨论】:
-
A
Label并不意味着显示多行文本。您是否尝试过使用Textblock? (别忘了设置PropertyTextWrapping="Wrap") -
@LittleBit,刚刚切换到文本块,当前问题已修复。试图弄清楚如何在文本块中居中文本?我第一次使用 WPF 从 Windows 窗体切换。属性中的水平和垂直对齐无效。
-
您在寻找
TextAlignment="Center"属性吗?