2017-12-18 279 views
0

我很頭痛,試圖在鼠標移過它時改變按鈕的默認行爲。下面是部分代碼: (我省略的代碼,各種面板,並只保留代碼感興趣的面板)爲什麼此XAML無法按預期工作?

<Window.Resources> 
    <Style x:Key="leftPanelButtons" TargetType="{x:Type Button}"> 
     .... various setters go here .... 
     <Setter Property="Background" Value="ForestGreen"/> 

     <Style.Triggers> 
      <Trigger Property="IsMouseOver" Value="True"> 
       <Setter Property="Background" Value="DarkSeaGreen"/> 
      </Trigger> 
     </Style.Triggers> 

    </Style> 

</Window.Resources> 

<DockPanel Grid.Row="2"> 
     <DockPanel Height="Auto" Width="Auto" VerticalAlignment="Stretch"> 
      <UniformGrid Columns="1" Height="Auto" VerticalAlignment="Stretch" MinWidth="150" Width="Auto"> 
       <UniformGrid.Resources> 
        <Style BasedOn="{StaticResource leftPanelButtons}" TargetType="Button"/> 
       </UniformGrid.Resources> 

       <Button> 
        button1 
       </Button> 

       <Button> 
        button2 
       </Button> 

       <Button> 
        button3 
       </Button> 

      </UniformGrid> 

      <StackPanel Height="Auto" Width="Auto" Background="PaleGoldenRod"> 

      </StackPanel> 
     </DockPanel> 
    </DockPanel> 

我期待按鈕的背景顏色設置爲森林綠和變化當鼠標移動到按鈕上時,轉到DarkSeaGreen。我確實獲得了ForestGreen顏色,但是當我將鼠標移動到按鈕上時,顏色變爲淺藍色變體。我有點複製了這個page的代碼。

回答

相關問題