这是我目前正在使用的代码:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="ButtonPrototype.MainPage"
Width="640" Height="480">
<UserControl.Resources>
<ControlTemplate x:Key="CellTemplate" TargetType="Button">
<Grid>
<Border x:Name="CellBorderBrush" BorderBrush="Black" BorderThickness="1">
<ContentPresenter
Content="{TemplateBinding Content}"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Border>
</Grid>
</ControlTemplate>
<Style x:Key="CellStyle" TargetType="Button">
<Setter Property="Template" Value="{StaticResource CellTemplate}"></Setter>
<Setter Property="Foreground" Value="Black"></Setter>
<Setter Property="FontSize" Value="80"></Setter>
<Setter Property="Width" Value="100"></Setter>
<Setter Property="Height" Value="100"></Setter>
</Style>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<Button Content="A" Style="{StaticResource CellStyle}"></Button>
</Grid>
</UserControl>
水平对齐可以正常工作,但是垂直对齐没有任何作用。感谢您的帮助。