D
D
Denis Mashanov2016-07-17 21:12:09
XAML
Denis Mashanov, 2016-07-17 21:12:09

How to change the background of a button when hovering the mouse over it?

Please help me change the white background of the "Delete" button to transparent or some other color when you hover over it with the mouse pointer. I searched everywhere and could not find an answer to my problem.
ZI9VLvCyIF

<Style x:Key="Button">
            <Setter Property="Button.Foreground" Value="Red"></Setter>  <!--установка цвета при загруке-->
            <Setter Property="Button.Background" Value="#00ABADB3"></Setter> <!--установка цвета при загруке-->
            <Style.Triggers>
                <Trigger Property="Button.IsMouseOver" Value="true">  <!--при наведении--> 
                    <Setter Property="Button.Foreground" Value="White"/>
                    <Setter Property="Button.Background" Value="#01ABADB3"/>
                </Trigger>
                <Trigger Property="Button.IsPressed" Value="true">  <!--при нажатии-->
                    <Setter Property="Button.Foreground" Value="Blue"/>
                </Trigger>
            </Style.Triggers>
        </Style>
 <Grid>
        <Button Style="{StaticResource Button}" Content="Удалить" Margin="419,457,10,10"  BorderBrush="#00707070" FontStyle="Italic"/>
        <Button Style="{StaticResource Button}" Content="Удалить всё" Margin="10,457,411,10" BorderBrush="#00707070" FontStyle="Italic"/>
    </Grid>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Mashanov, 2016-07-18
@LoneRay

Solved the problem in this way.

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApplication1"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <Style x:Key="DelAll">
            <Setter Property="Button.Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Grid>
                            <Border Name="Head">
                                <Rectangle HorizontalAlignment="Stretch"  VerticalAlignment="Stretch"  Fill="Transparent" />
                            </Border>
                            <Label Name="NameLable" Content="Удалить всё" FontStyle="Italic" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Red"></Label>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter TargetName="Head" Property="Background" Value="#3500ACFF"/>
                                <Setter TargetName="Head" Property="BorderBrush" Value="#FF00ACFF"/>
                                <Setter TargetName="Head" Property="BorderThickness" Value="1,1,1,1"/>
                                <Setter TargetName="NameLable" Property="Foreground" Value="Blue"/>
                            </Trigger>
                            <Trigger Property="IsMouseDirectlyOver" Value="true">
                                <Setter TargetName="NameLable" Property="Foreground" Value="White"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="Del">
            <Setter Property="Button.Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Grid>
                            <Border Name="Head">
                                <Rectangle HorizontalAlignment="Stretch"  VerticalAlignment="Stretch"  Fill="Transparent" />
                            </Border>
                            <Label Name="NameLable" Content="Удалить" FontStyle="Italic" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Yellow"></Label>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter TargetName="Head" Property="Background" Value="#3500ACFF"/>
                                <Setter TargetName="Head" Property="BorderBrush" Value="#FF00ACFF"/>
                                <Setter TargetName="Head" Property="BorderThickness" Value="1,1,1,1"/>
                                <Setter TargetName="NameLable" Property="Foreground" Value="Green"/>
                            </Trigger>
                            <Trigger Property="IsMouseDirectlyOver" Value="true">
                                <Setter TargetName="NameLable" Property="Foreground" Value="White"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Window.Background>
        <ImageBrush/>
    </Window.Background>
    <Grid>
        <Button Style="{StaticResource DelAll}" HorizontalAlignment="Left"  Width="150" Height="50" Margin="95,49,0,0" VerticalAlignment="Top"/>
        <Button Style="{StaticResource Del}" HorizontalAlignment="Left"  Width="150" Height="50" Margin="95,200,0,0" VerticalAlignment="Top"/>
    </Grid>    
</Window>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question