How to remove Glow of Button on Mouse hover in WPF

后端 未结 1 1175
天命终不由人
天命终不由人 2020-12-30 09:54

I am using a simple button in WPF. I have put an image for the button on background. My problem is, when i move mouse pointer to button it get a default glow and override th

相关标签:
1条回答
  • 2020-12-30 10:51

    It's defined in Button's ControlTemplate. You should create your own.

    for example like this.

    <Style x:Key="MyButtonStyle" TargetType="Button">
      <Setter Property="Template">
         <Setter.Value>
            <ControlTemplate TargetType="Button">
               <Grid Background="{TemplateBinding Background}">
                  <ContentPresenter HorizontalAlignment="Center"
                            VerticalAlignment="Center"/>
               </Grid>
            </ControlTemplate>
         </Setter.Value>
      </Setter>
    </Style>
    

    Then you can apply this style to your Button. and set Background to that image of yours.

    <Button Style="{StaticResource MyButtonStyle}" Grid.Column="3" Name="Play" BorderBrush="Transparent"
            Focusable="False" Width="45" Height="45" Click="Play_Click"
            VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,6,10,6">
            <Button.Background >
                <ImageBrush ImageSource="images/play.png"  />
            </Button.Background>
    </Button>
    
    0 讨论(0)
提交回复
热议问题