Daniel G
Daniel G

Reputation: 29

WPF IsMouseOver trigger, hitbox for trigger isn't over the button

I have defined a custom template for a button including a border and a textblock, as shown here:

<Style x:Key="WindowControlButtons" BasedOn="{StaticResource WindowControlButtonsFont}" TargetType="{x:Type Button}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                <Border Padding="{TemplateBinding Padding}" Height="100" Background="Yellow">
                    <TextBlock Text="{TemplateBinding Content}" />
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>

    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Foreground" Value="{StaticResource FgOrangeBrush}" />
        </Trigger>

    </Style.Triggers>
</Style>

I am trying to get it to change to an orange foreground when I hover, and it works (sort of). It only registers my "mouseover" when my mouse is between about 5-30 pixels below the actual label. The yellow background on the border was for me to visualize the button, but it would normally be transparent. Here is a screenshot of two instances of the button:

Snip of the relevant part of the app

I have included a blue outline of approximately where the hover triggers the IsMouseOver trigger.

Basically, I want to know why the trigger isn't triggering on most of the button. In case it helps, here are the declarations of the buttons:

<Button HorizontalAlignment="Right" Margin="10 0" Grid.Column="2" Content="X" Style="{StaticResource WindowControlButtons}" />
                <Button HorizontalAlignment="Right" Margin="35 0" Grid.Column="2" Content="_" Style="{StaticResource WindowControlButtons}" />

Thank you very much!

Upvotes: 0

Views: 713

Answers (1)

Daniel G
Daniel G

Reputation: 29

Since I was using window chrome, some weird things happen to "hitboxes" when you don't add in this to the style:

<Setter Property="WindowChrome.IsHitTestVisibleInChrome" Value="True" />

Upvotes: 1

Related Questions