WPF Border IsMouseOver not working

I defined this style in app.xaml:

<Style x:Key="RedCloseButton" TargetType="Border"> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Border.Background" Value="Yellow" /> </Trigger> <Trigger Property="IsMouseOver" Value="False"> <Setter Property="Border.Background" Value="Black" /> </Trigger> </Style.Triggers> </Style> 

And I'm trying to use it in another xaml file, for example:

  <Border Style="{StaticResource RedCloseButton}" Name="ClearValue" BorderThickness="2" BorderBrush="black" CornerRadius="0,4,4,0" Margin="110,90,0,80" Background="#FF801F1F"> <Rectangle Margin="10,11,6,10" Fill="White" RadiusX="2" RadiusY="2" IsHitTestVisible="False"></Rectangle> </Border> 

But nothing happens when I smoke over the border. What could be wrong here?

+6
source share
1 answer

This is because you set Background to Border , it will override Style

You need to remove Background="#FF801F1F" from Border xaml so that Style can set Background

 <Border Style="{StaticResource RedCloseButton}" Name="ClearValue" BorderThickness="2" BorderBrush="black" CornerRadius="0,4,4,0" Margin="110,90,0,80"> <Rectangle Margin="10,11,6,10" Fill="White" RadiusX="2" RadiusY="2" IsHitTestVisible="False"></Rectangle> </Border> 
+13
source

All Articles