Answer the question
In order to leave comments, you need to log in
How to change button background in WPF on mouse hover?
Hey! There is a problem with the fact that I am trying to add styles to a button. All work fine, except for the background change on hover. I register a trigger with a background color change, but it does not change the color to the one I specified. I understand that there is some standard style that sets the background on hover, which I cannot change.
<Application.Resources>
<Style x:Key="cdButton" TargetType="Button">
<Setter Property="Background" Value="#3D5754" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Red" />
</Trigger>
</Style.Triggers>
</Style>
</Application.Resources>
<Button Content="Войти" Margin="0 20" Click="button_Sign_Click" Style="{StaticResource cdButton}" >
Answer the question
In order to leave comments, you need to log in
You need to change the button template and bind the button background color with the border background color:
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="#3D5754"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question