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?
A:
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>
Amod
2010-06-24 09:59:57
Amod Kumar Chandra
Amod
2010-06-24 10:00:56
A:
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.
Kishore Kumar
2010-06-24 10:10:22
A:
Class Style has property BasedOn and the constructor accepting Style parameter which defines style to be based on.
Style boldStyle = new Style(typeof(Button), generalButtonStyle);
brain_pusher
2010-06-24 10:19:13