Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Border IsMouseOver trigger not working

Tags:

wpf

xaml

I have defined this kind of 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 like this:

    <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 mouse over the border.. what could be wrong here?

like image 994
Jaska Avatar asked Mar 05 '13 20:03

Jaska


1 Answers

Its because you have set the Background in the Border, this will override the Style

You will have to remove Background="#FF801F1F" from the Border xaml so the Style can set the 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>       
like image 138
sa_ddam213 Avatar answered Sep 19 '22 16:09

sa_ddam213