Button Color WPF

前端 未结 1 561
野趣味
野趣味 2021-01-27 12:58

I\'m trying to change my button color when the mouse is over it but it\'s not working (the button is still blue) and all examples I find go like I\'m doing:

<         


        
相关标签:
1条回答
  • 2021-01-27 14:02

    You should use ControlTemplate for this purpose like this:

    <Button.Style>
         <Style TargetType="{x:Type Button}">
              <Setter Property="Background" Value="#424242"/>
              <Setter Property="Template">
                  <Setter.Value>
                      <ControlTemplate TargetType="{x:Type Button}">
                           <Border Background="{TemplateBinding Background}">
                              <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                          </Border>
                      </ControlTemplate>
                  </Setter.Value>
             </Setter>
             <Style.Triggers>
                 <Trigger Property="IsMouseOver" Value="True">
                     <Setter Property="Background" Value="#8BC34A"/>
                 </Trigger>
               </Style.Triggers>
         </Style>
    </Button.Style>
    
    0 讨论(0)
提交回复
热议问题