hello there is a code

<Application.Resources> <Style TargetType="Button" x:Key="style"> <Style.Triggers> <Trigger Property="IsPressed" Value="true"> <Setter Property="Background" Value="Black"/> <Setter Property="BorderBrush" Value="Blue"/> <Setter Property="BorderThickness" Value="3"/> </Trigger> </Style.Triggers> <Style.Setters> <Setter Property="Background" Value="Red"/> <Setter Property="BorderBrush" Value="Blue"/> <Setter Property="BorderThickness" Value="10"/> </Style.Setters> </Style> </Application.Resources> 

written in the app.xaml file; Po only works for some reason Background Other styles do not work for some reason what I do wrong Button

 <Button Style="{StaticResource style}" Height="100" Width="300"/> 
  • Your example works for me. - sp7
  • how can it be .. and - Sasuke
  • I deceived you, I noticed that not all styles are picked up) - sp7
  • Well, not only does the background work for you? - Sasuke
  • Added an example of how you can achieve the desired result, I hope that will help you. - sp7

1 answer 1

In order for your example to work, you must completely override the inherited Windows style for the buttons. In your case, the code should look something like this:

 <Style TargetType="{x:Type Button}" x:Key="style"> <Setter Property="Background" Value="Red"/> <Setter Property="BorderBrush" Value="Blue"/> <Setter Property="BorderThickness" Value="10"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" /> </Border> </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <Trigger Property="IsPressed" Value="True"> <Setter Property="Background" Value="Black" /> <Setter Property="BorderBrush" Value="Blue" /> <Setter Property="BorderThickness" Value="3" /> </Trigger> </Style.Triggers> </Style> 
  • thanks yes works - Sasuke