How do you align text so it is in the middle of a button in Silverlight?
- by Roy
Here is the current code I am using:
<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>
The Horizontal aligning works but the verticalalignment doesn't do anything. Thanks for your help.