Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove Glow of Button on Mouse hover in WPF

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 the image given as background.

        <Button 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.Foreground>
                <ImageBrush ImageSource="images/play.png"  />
            </Button.Foreground>
        </Button>

Please help me.

like image 920
Sarin Vadakkey Thayyil Avatar asked Aug 08 '13 09:08

Sarin Vadakkey Thayyil


1 Answers

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>
like image 161
Kapitán Mlíko Avatar answered Sep 22 '22 11:09

Kapitán Mlíko