In my C#/WPF/.NET 4.5 application I have buttons with images that I implemented in the following fashion:
<Button Style="{StaticResource BigButton}">
<StackPanel>
<Image Source="Images/Buttons/bt_big_save.png" />
<TextBlock>save</TextBlock>
</StackPanel>
</Button>
I have a resource dictionary UIStyles.xaml in which I declare the following:
<Style TargetType="Button" x:Key="BigButton">
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Height" Value="80" />
<Setter Property="Width" Value="80" />
<Setter Property="Foreground" Value="White" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border x:Name="border"
CornerRadius="5"
Background="#FF415360">
<ContentPresenter x:Name="ButtonContentPresenter"
VerticalAlignment="Center"
HorizontalAlignment="Center">
<ContentPresenter.Resources>
<Style TargetType="TextBlock">
<Setter Property="TextAlignment" Value="Center" />
</Style>
<Style TargetType="Image">
<Setter Property="Width" Value="10" />
<Setter Property="Margin" Value="10" />
</Style>
</ContentPresenter.Resources>
</ContentPresenter>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The cursor, height, border etc. properties work fine, but I can't style the TextBlock
and the Image
.
Specifically, what needs to look like this:
Ends up looking like this (disregarding the color difference):
I've seen similar questions asked before but the solutions used different approaches (I don't want to create a custom User Control, all of my needs except this one are covered in the present code and re-writing will be a nuisance). I merely need to fix my Style
so that the TextBlock
is centered and the Image
is centered and made smaller.
How do I re-write the Style
to correct the look of my buttons?