WPF - Change the color of a button when the mouse is on top

0

Good, how can I apply a style to a button when the mouse passes over:

This would be my code to apply the style to my button:

<Window.Resources>
        <Style TargetType="Button" x:Key="TabButtonFirst">
            <Setter Property="Template" >
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border CornerRadius="15,15,15,15"  BorderBrush="#D3F2EE" BorderThickness="2,2,2,0" Background="#FF57CDBD" >
                            <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                            <Border.Style>
                                <Style TargetType="{x:Type Border}">
                                    <Style.Triggers>
                                        <Trigger Property="IsMouseOver" Value="True">
                                            <Setter Property="Background" Value="#3A887E"/>
                                        </Trigger>
                                    </Style.Triggers>
                                </Style>
                            </Border.Style>
                        </Border>

                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>

My button:

<Button x:Name="button1" Style="{StaticResource TabButtonFirst}" Content="INGRESAR" HorizontalAlignment="Left" Margin="54,340,0,0" VerticalAlignment="Top" Width="97" FontFamily="Century Gothic" FontWeight="Bold" Height="25" Foreground="White" BorderThickness="0" RenderTransformOrigin="0.5,0.5" Background="#FFAEF1E8" BorderBrush="#FFF7F7F7"/>
    
asked by Raphael 23.02.2017 в 23:32
source

1 answer

0

You have re-established the background in the definition of the button, so you are invalidating the one you have defined within the style. Remove the background property from the button definition ( button1 ) and it will work. On the other hand I see that you have defined the style in the same window, read about the creation of dictionaries where you can agglutinate the different styles used in the application. They will offer you greater control and will be easier to manage in the event that some day you want to give your application different skins .

    
answered by 13.03.2017 / 13:52
source