-1

The button highlights only when my mouse is over the text, I want it to highlight when my mouse is over the button.

<Button Content="Characters" Click="BtnClickP1" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="124" Height="50" HorizontalContentAlignment="Left" BorderBrush="{x:Null}" Foreground="White">
            <Button.Style>
                <Style TargetType="{x:Type Button}">
                    <Setter Property="BorderBrush" Value="Transparent"/>
                    <Setter Property="Background" Value="{x:Null}"/>
                    <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="#FF282A30"/>
                        </Trigger>
                        <Trigger Property="IsFocused" Value="True">
                            <Setter Property="Background" Value="#FF282A30"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </Button.Style>
        </Button>
ASh
  • 34,632
  • 9
  • 60
  • 82
Tadayo
  • 1
  • 1
  • don't set {x:Null} Background. https://stackoverflow.com/questions/5344699/xnull-vs-transparent – ASh Aug 22 '19 at 08:18

2 Answers2

1

Your code is already working, however a null background affects the MouseOver event.

<Button Content="Characters" Click="Button_Click" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="124" Height="50" HorizontalContentAlignment="Left" BorderBrush="{x:Null}" Foreground="White">
    <Button.Style>
        <Style TargetType="{x:Type Button}">
            <Setter Property="BorderBrush" Value="Transparent"/>
            <Setter Property="Background" Value="Transparent"/> <!-- Here to Transparent -->
            <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="#FF282A30"/>
                </Trigger>
                <Trigger Property="IsFocused" Value="True">
                    <Setter Property="Background" Value="#FF282A30"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </Button.Style>
</Button>
IvanJazz
  • 763
  • 1
  • 7
  • 19
0

You have to set the Background Transparent.

Tarboeuf
  • 90
  • 4
  • no, they don't have to set the Background Transparent. it can be any brush, not just SolidColorBrush – ASh Aug 22 '19 at 08:19
  • when i do this nothing highlights at all edit nvm i got it – Tadayo Aug 22 '19 at 08:25
  • I have just tried it with this code, it seems to work ` – Tarboeuf Aug 22 '19 at 08:34