0

I am designing the GUI for my WPF app. I have a button that has a custom image as the background. When the mouse rolls over the button, I want the background to change to a solid color. In my current code, the Foreground property works as expected, but the background property does not change anything. When the mouse rolls over, the background changes to the default rollover background. Why won't this work?

Here is my app.xaml:

       <Style x:Key="MainMenuButton" TargetType="Button">
            <Setter Property="Background">
                <Setter.Value>
                    <ImageBrush ImageSource="assets/img/mainMenuButton.png" Stretch="UniformToFill"/>
                </Setter.Value>
            </Setter>
            <Setter Property="FontFamily" Value="Franklin Gothic Book" />
            <Setter Property="Padding" Value="8" />
            <Setter Property="Margin" Value="0" />
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="FontSize" Value="24"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="Width" Value="322"/>
            <Setter Property="Height" Value="73"/>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="White"/>
                    <Setter Property="Foreground" Value="Black"/>
                </Trigger>
            </Style.Triggers>
        </Style>
Ugur
  • 1,257
  • 2
  • 20
  • 30
ShoeLace1291
  • 4,551
  • 12
  • 45
  • 81
  • 3
    Long story short: You need to edit the ControlTemplate. Afaik there is no other option – lokusking Sep 27 '16 at 13:31
  • @lokusking is correct, the problem is the default ControlTemplate for a Button implements some default mouse-over behavior that uses system colors, and the only way to remove/change that is to implement a new ControlTemplate that removes that behavior. See [this question](http://stackoverflow.com/q/3854317/302677) for some examples. – Rachel Sep 27 '16 at 15:15

0 Answers0