2013-03-05 92 views
6

我在App.xaml中定義的這種風格:WPF邊境IsMouseOver觸發器不工作

<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> 

我試圖在另一個XAML -file像這樣使用它:

<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> 

但是,當我將鼠標移到邊界上時什麼都沒有發生......這裏可能有什麼錯誤?

回答

13

它,因爲你已經在Border設置Background,這將覆蓋Style

你將不得不從Borderxaml刪除Background="#FF801F1F"所以Style可以設置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>  
+0

是啊,做了魔術!非常感謝! – Jaska 2013-03-05 20:30:30