3

I have a button, as such:

<Button HorizontalAlignment="Left" Margin="0,55,0,0" VerticalAlignment="Top" Width="350" Click="StartProcedure_Click" BorderThickness="0" Height="60" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" HorizontalContentAlignment="Left" ScrollViewer.VerticalScrollBarVisibility="Disabled" VerticalContentAlignment="Center" Padding="10,1,0,0" IsHitTestVisible="True">
            <StackPanel Orientation="Horizontal">
                <Image Source="resources\img_xraystarticon.png" Width="50" Height="50"/>
                <TextBlock TextElement.Foreground="#6a6869" Padding="5,0,0,0" VerticalAlignment="Center" FontSize="30" FontFamily="Century Gothic">Start Procedure</TextBlock>
            </StackPanel>
            <Button.Background>
                <ImageBrush ImageSource="resources\img_emptyrectbutton.png"/>
            </Button.Background>
        </Button>

Where I applied the Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" style to remove the mouseover effects defaulting with the Button. However, I still continue to experience a mouseover effect, as shown here:

enter image description here

Prior to Mouseover, and with Mouseover:

enter image description here

I have attempted to override the MouseEnter event with no success (I have confirmed my MouseEnter event is triggered but I can't seem to negate the property that is set with MouseEnter by default with the above).

What do I need to do to avoid the above?

Thanks!

EDIT:

I have entered the below code but I am now unable to get a MouseEnter function to execute properly (I want the text to change colors but I am not seeing it happen):

<Button Name="Button_StartMenu" HorizontalAlignment="Left" Margin="0,55,0,0" VerticalAlignment="Top" Width="350" Click="StartProcedure_Click" BorderThickness="0" Height="60" HorizontalContentAlignment="Left" ScrollViewer.VerticalScrollBarVisibility="Disabled" VerticalContentAlignment="Center" Padding="10,1,0,0" IsHitTestVisible="True" MouseEnter="Button_MouseEnter">
            <Button.Background>
                <ImageBrush ImageSource="resources\img_emptyrectbutton.png"/>
            </Button.Background>
            <Button.Style>
                <Style TargetType="{x:Type Button}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type Button}">
                                <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
                                    <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                </Border>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Button.Style>
            <StackPanel Orientation="Horizontal">
                <Image Source="resources\img_xraystarticon.png" Width="50" Height="50"/>
                <TextBlock TextElement.Foreground="#6a6869" Padding="5,0,0,0" VerticalAlignment="Center" FontSize="30" FontFamily="Century Gothic"><Run Text="Start Procedure"/></TextBlock>
            </StackPanel>
        </Button>
RootAtShell
  • 115
  • 1
  • 7

1 Answers1

1

Instead of trying to 'prevent' it I would define the mouseover event to display the same as the non-mouseover. You can set them both to be the same and while it will still switch, visually it appears the same.

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

       <Button.Style>
            <Style TargetType="Button">
                <Setter Property="Background" Value="Green"/>
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Background" Value="Green"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Button.Style>
Community
  • 1
  • 1
bowlturner
  • 1,968
  • 4
  • 23
  • 35
  • I updated my above code which got rid of the mouseenter effect of highlighting but it now prevents any mouseenter effect from taking hold, even when I am calling Button_StartMenu.Foreground = Brushes.Green from MouseEnter.. – RootAtShell Aug 06 '14 at 20:21
  • You'll have to set that in the trigger section. You can make a style that can be reused instead of putting all the properties on this specific button. – bowlturner Aug 06 '14 at 20:32
  • Even if I enclose the Style.Triggers into my property for the button, I am still having the same issue - it doesn't trigger with the above code. Your code above doesn't help with it. – RootAtShell Aug 06 '14 at 20:41
  • Sorry that's the best I can do. I know how much of these things are supposed to work, but I usually need some trial and error to get everything to work as expected. – bowlturner Aug 06 '14 at 20:47
  • Well, have an upvote for helping, at least. I'll continue playing with it. – RootAtShell Aug 06 '14 at 20:52
  • Thanks! And sorry it wasn't more help. – bowlturner Aug 06 '14 at 20:54
  • What about for Windows Universal? Style.triggers are no longer present. – matthewsheets Jul 20 '15 at 22:24