1

I tried all the other solutions found on this site or on others but it doesn't work. Here is button:

<Button Grid.Row="1" Grid.Column="0" HorizontalAlignment="Stretch" 
            VerticalAlignment="Stretch" Margin="10,10,5,10" BorderThickness="3">
    <Button.Background>
        <SolidColorBrush Opacity="0.0" Color="#b3b3b3"/>
    </Button.Background>
    <Button.BorderBrush>
        <SolidColorBrush Opacity="0.3" Color="Gray"/>
    </Button.BorderBrush>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="5*"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
    </Grid>
</Button>

What I tried:

Addig a style in the Windows.Resources:

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

And adding this inside the button as well. The two solutions I got was either nothing, the old highlighted look, or an error that I can't change the Content twice. As I'm out of ideas, could someone show me how to change my button's highlighted look?

EDIT:

copied character by character from the thread I mentioned in my answer:

<Button Content="Button" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="50" Height="50" HorizontalContentAlignment="Left" BorderBrush="{x:Null}" Foreground="{x:Null}" Margin="50,0,0,0">
        <Button.Style>
            <Style TargetType="{x:Type Button}">
                <Setter Property="Background" Value="Green"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Button}">
                            <Border Background="{TemplateBinding Background}">
                                <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Background" Value="DarkGoldenrod"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Button.Style>
    </Button>

Now it works. The reason it didn't was that my own button - in this question - had some of its own properties, like those brushes and the grid.

agiro
  • 2,018
  • 2
  • 30
  • 62
  • Is that the entire style you added to `Window.Resources`? Just a disembodied `Style.Triggers`? Whether or not that's the case, no style can override the Background you're setting on the Button itself. Anyway, if you want to change the highlight behavior, go back to all of the answers you tried, and try one of the ones that shows you how to replace the template. – 15ee8f99-57ff-4f92-890c-b56153 Feb 24 '17 at 18:49
  • I tried both only this (I added this here as this was tried the last) and I tried adding everything with the `ControlTemplate`. So you say it doesn't work because my button overrides what I add by its own style and I shall add everything from the `template`? – agiro Feb 24 '17 at 19:05
  • Well the reason it didn't work was what I said in the prior comment - my buttons already defined their own styles and the template just ignored it and on a bare button it works. However, I'd like you to watch your tone in these comments. I know you are more skilled than I on this, but if you don't feel like helping, then just don't. – agiro Feb 24 '17 at 19:15
  • As you wish. The issue is solved though, anyone messing up like me may find this so after all the thread might be helpful. – agiro Feb 24 '17 at 19:22
  • If you had provided enough XAML to recreate what you were actually doing, it would've been easy to solve. I'm left guessing at everything, though. It's starting to sound like you defined the new template in an implicit style, while setting a different style explicitly on the actual buttons? The `Button` tag in your question doesn't have a style explicitly set. – 15ee8f99-57ff-4f92-890c-b56153 Feb 24 '17 at 19:25
  • True that one, reading it over again the thread was sloppy. By _having their own style_ I meant those `brushes` inside the button and the `grid`. I need that grid as the button will be a `tile` with an image and some info texts. But after leaving the button in my answer and using the unstripped style from the answer I linked in mine, it's working fine. – agiro Feb 24 '17 at 19:32

1 Answers1

0

Update: all solutions would work, the reason they didn't for me is that my buttons define their own style inside of them. Once I commented my old buttons out and added a bare button like this:

EDIT:

Here I said define their own style. It was a wrong way to call it, I meant the brushes and the grid by it.

This thread did the trick.

Community
  • 1
  • 1
agiro
  • 2,018
  • 2
  • 30
  • 62