I've created a button inside a window. For an easier usage, I want to convert the button into a style.
The button in the window file
<Button x:Name="btn_CustomButton"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
Padding="0,10,0,7"
HorizontalContentAlignment="Stretch"
BorderBrush="{x:Null}"
Background="#FF2E2E2E"
Margin="0,0,0,1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Source="UIExplorer_64x.png" Margin="10,0,0,0" Stretch="UniformToFill" />
<Label Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,0,0,2" FontSize="18" Foreground="#FFD6D6D6" Padding="0" >btn_CustomButton</Label>
</Grid>
</Button>
The style I tried:
<Style x:Key="NavigationButton" TargetType="{x:Type Button}">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="Background" Value="#FF2E2E2E" />
<Setter Property="Padding" Value="0,10,0,7"/>
<Setter Property="Margin" Value="0,0,0,1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid Width="{TemplateBinding Width}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Source="UIExplorer_64x.png" Margin="10,0,0,0" Stretch="UniformToFill" />
<Label Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,0,0,2" FontSize="18" Foreground="#FFD6D6D6" Padding="0" >btn_CustomButton</Label>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The problem is, the style seems to ignore some attributes like the background color and also the padding.
What it should look like:
What it does look like:
It's hard to see the difference, but the style actually ignores the background color.
Also, how could I send the image path to the button so I could use
<button Style="{StaticResource NavigationButton}"
Content="Text"
ImageSource="someImage.png" />
Since I'm new in learning wpf styling, any help is appreciated :)