In Wpf how to avoid/disable mouse hover a button highlight color ?

Chocolade 516 Reputation points
<Button x:Name="btnWatcher" Content="Start Watching" HorizontalAlignment="Left" Margin="14,241,0,0" VerticalAlignment="Top" Width="109" RenderTransformOrigin="0.484,-0.066" Height="30" FontSize="16" Background="#FFFB0000" Click="btnWatcher_Click"/>
        <TextBox HorizontalAlignment="Left" Height="30" Margin="14,175,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="644"/>
        <Button Content="Browse" Margin="673,175,18,0" VerticalAlignment="Top" RenderTransformOrigin="-0.111,0.769" Height="30" FontSize="16"/>

I wonder if there is a way to do it for all the future buttons and other controls or do i need to make a solution for each control/button ? And how to do it ?

I want to disable the mouse hove highlight.

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,710 questions
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
789 questions
0 comments No comments
{count} votes

Accepted answer
  1. Hui Liu-MSFT 47,336 Reputation points Microsoft Vendor

    You could override ControlTemplate. When you override it, you're going to reimplement behaviors (visual states) triggered by user interaction such as pressed, mouseover, disabled.

            <ControlTemplate x:Key="NoMouseOverButtonTemplate"   
                <Border Background="{TemplateBinding Background}"  
              BorderBrush="{TemplateBinding BorderBrush}"  
              BorderThickness="{TemplateBinding BorderThickness}">  
                    <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"  
                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />  
                    <Trigger Property="IsEnabled"  
                        <Setter Property="Background"  
                  Value="{x:Static SystemColors.ControlLightBrush}" />  
                        <Setter Property="Foreground"  
                  Value="{x:Static SystemColors.GrayTextBrush}" />  
            <Button  Width="100" Height="50" Content="click" Template="{StaticResource NoMouseOverButtonTemplate}" />  
            <Button  Width="100" Height="50" Content="click"  />  

    To know the required elements contained in the ControlTemplate that are mandatory for the templated control to perform as expected
    You could refer to the Control Styles and Templates page (in your case the Button Styles and Templates page) and check for named parts as some controls require certain elements to carry a certain name in order to be identified.
    You can also use the default template provided there as a starting point to design or customize controls.

    The result:


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    2 people found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful