通过 XAML 有几种方法可以做到这一点:
- 添加一个带有换行符的 TextBlock:
<Button>
<TextBlock TextAlignment="Center">Line 1<LineBreak/>Line 2</TextBlock>
</Button>
- 在文本中添加换行符:
这种方法很简单,但没有办法轻松控制文本的对齐方式:
<Button Content="Line 1 
 Line 2"/>
- 添加文本块并环绕文本
一旦 Buttons 的大小小于 TextBlocks 的大小,它就会自动将内容分成两行或更多行
<Button>
<TextBlock TextWrapping="Wrap" HorizontalAlignment="Center">Line 1 Line 2</TextBlock>
</Button>
- 可以在您的 Button 中使用 StackPanel,并将每一行添加为文本块:
<Button>
<StackPanel>
<TextBlock Text="Line1" HorizontalAlignment="Center"/>
<TextBlock Text="Line2" HorizontalAlignment="Center"/>
</StackPanel>
</Button>
- 在您的按钮中使用网格:
<Button>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Text="Line1" HorizontalAlignment="Center"/>
<TextBlock Text="Line2" HorizontalAlignment="Center"/>
</Grid>
</Button>
- 我敢肯定还有更多,列表基本上是从最喜欢到最不喜欢的顺序。