LoneRay
@LoneRay
Начинающий кодировщик.

Как изменить фон у button при наведении указателя мыши на него?

Помогите пожалуйста изменить белый фон кнопки "Удалить" на прозрачный или другой какой-либо цвет при наведении на него указателя мыши. Везде искал и не смог к своей задаче найти ответ.
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>
  • Вопрос задан
  • 5356 просмотров
Решения вопроса 1
LoneRay
@LoneRay Автор вопроса
Начинающий кодировщик.
Решил проблему таким образом.
<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>
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы