0

WPF: i have a button and the image was set in code behind c#

 btn.Content = new Image
                    {
                        Source = new BitmapImage(new Uri(MasterVariables.applicationPath + "Normal.png")),
                        Stretch = Stretch.Fill,
                    };

now problem is while over into the button the background color set as blue but i change the image in mouse_enter event

 btn.BorderThickness = new Thickness(0);
            btn.Style = (Style)FindResource(ToolBar.ButtonStyleKey);
            btn.Background = Brushes.White; btn.BorderBrush = Brushes.Transparent;
           btn.Content = new Image
                    {
                        Source = new BitmapImage(new Uri(MasterVariables.applicationPath + "Hover.png")),
                        Stretch = Stretch.Fill,
                    };

the image was change but while over into mouse the backgrounded is highlighted in blue color

Cœur
  • 37,241
  • 25
  • 195
  • 267
Mohana s
  • 47
  • 1
  • 9

2 Answers2

0

Update your style to trigger background on MouseOver:

<Style.Triggers>
    <Trigger Property='IsMouseOver' Value='True'>
        <Setter Property='Background' Value='White' />
    </Trigger>
</Style.Triggers>
James Lucas
  • 2,452
  • 10
  • 15
0

Try this

 <ControlTemplate.Triggers>
                            <Trigger Property="IsPressed" Value="true">
                                <Setter Property="Background" Value="Gray" TargetName="panel" />
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="Background" Value="LightGray" />
                            </Trigger>
                        </ControlTemplate.Triggers>

and more information refer this sites

How do you change Background for a Button MouseOver in WPF?

Transparent button background in WPF using style

Community
  • 1
  • 1
Pradnya Bolli
  • 1,915
  • 1
  • 19
  • 37