0

I'm having a headache trying to change the default behavior of a button when the mouse moves over it. Here is part of the code: (I've omitted the code for various panels and kept only the code for the panel of interest)

<Window.Resources>
    <Style x:Key="leftPanelButtons" TargetType="{x:Type Button}">
        .... various setters go here ....
        <Setter Property="Background" Value="ForestGreen"/>

        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background" Value="DarkSeaGreen"/>
            </Trigger>
        </Style.Triggers>

    </Style>

</Window.Resources>

<DockPanel Grid.Row="2">
        <DockPanel Height="Auto" Width="Auto" VerticalAlignment="Stretch">
            <UniformGrid Columns="1" Height="Auto" VerticalAlignment="Stretch" MinWidth="150" Width="Auto">
                <UniformGrid.Resources>
                    <Style BasedOn="{StaticResource leftPanelButtons}" TargetType="Button"/>
                </UniformGrid.Resources>

                <Button>
                    button1
                </Button>

                <Button>
                    button2
                </Button>

                <Button>
                    button3
                </Button>

            </UniformGrid>

            <StackPanel Height="Auto" Width="Auto" Background="PaleGoldenRod">

            </StackPanel>
        </DockPanel>
    </DockPanel>

I was expecting the button background color to be set to ForestGreen and change to DarkSeaGreen when the mouse moved over the button. I do get the ForestGreen color but when I move the mouse over the button the color changes to a light blue variant. I've kind of copied the code from this page.

pzogr
  • 424
  • 1
  • 12
  • 30

1 Answers1

0

Yeah its a bit strange like that. To modify the Background of a Button on MouseOver you actually have to change the ControlTemplate. See here:

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

ATH
  • 36
  • 4