Click here to Skip to main content
15,890,717 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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.
I need to retain the button as it.

C#
<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>
Posted

You can Apply this style to your "Play" button..



XML
<Style x:Key="ButtonStyleNoHighlighting" TargetType="Button">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Grid Background="{TemplateBinding Background}">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="MouseOver"/>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


Hope this will help you
 
Share this answer
 
v4
Comments
Sarin VT 8-Aug-13 5:42am    
Thank you Punam. :)
Its working.
Joezer BH 8-Aug-13 5:45am    
5ed!
ridoy 8-Aug-13 5:51am    
good one,+5.
Laurent Chougrani 18-Jun-18 13:24pm    
You should add :

<Label Content="{TemplateBinding Content}">

after the <visualstatemanager.visualstategroups>, so that your content shows.
XML
If someone doesn't want to override default Control Template then here is the solution.

You can create DataTemplate for button which can have TextBlock and then you can write Property trigger on IsMouseOver property to disable mouse over effect. Height of TextBlock and Button should be same.



        <Button Background="Black" Margin="0" Padding="0" BorderThickness="0" Cursor="Hand" Height="20">
                        <Button.ContentTemplate>
                            <DataTemplate>
                                <TextBlock Text="GO" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center" TextDecorations="Underline" Margin="0" Padding="0" Height="20">
                                    <TextBlock.Style>
                                        <Style TargetType="TextBlock">
                                            <Style.Triggers>
                                                <Trigger Property ="IsMouseOver" Value="True">
                                                    <Setter Property= "Background" Value="Black"/>
                                                </Trigger>
                                            </Style.Triggers>
                                        </Style>
                                    </TextBlock.Style>
                                </TextBlock>
                            </DataTemplate>
                        </Button.ContentTemplate>
                    </Button>
 
Share this answer
 
v2
Another really quick and dirty workaround to disable glowing is to set
Focusable="False"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900