Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override general Button style

Tags:

wpf

xaml

We have a general style in default.xaml, targeting all buttons in our application. Is there a way to override this style, and creating a new button based on the default button?

like image 924
hhravn Avatar asked Jun 24 '10 09:06

hhravn


2 Answers

if you want to inherit any existing style use BasedOn

<Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}"   x:Key="RedTextBasedOnButton">  <Setter Property="Foreground" Value="Red" /> </Style>

this will inherit the default style and new foreground property will apply to the new style

hope this helps.

like image 151
Kishore Kumar Avatar answered Nov 08 '22 02:11

Kishore Kumar


You can change the Template of the Button like this

<Style x:Key="{x:Type Button}" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Padding="10,5,10,5" BorderBrush="Green" BorderThickness="1" CornerRadius="5" Background="#EFEFEF">
  <TextBlock Text="{TemplateBinding Content}" />
</Border>
</ControlTemplate>
</Style>
like image 3
Amod Avatar answered Nov 08 '22 02:11

Amod