Skip to content

Non-client area hit test feature doesn't work properly when view box is involved #222

@DoctorKrolic

Description

@DoctorKrolic

Steps to reproduce

A default WPF app with latest version of the library and the following xaml and code behind for main window:

<cz:WindowChromeWindow x:Class="TestWpfApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:cz="clr-namespace:ControlzEx;assembly=ControlzEx"
        xmlns:czb="clr-namespace:ControlzEx.Behaviors;assembly=ControlzEx"
        xmlns:local="clr-namespace:TestWpfApp"
        mc:Ignorable="d"
        WindowStartupLocation="CenterScreen"
        Title="MainWindow" Height="450" Width="800">
    <StackPanel Background="White" VerticalAlignment="Top" HorizontalAlignment="Right">
        <Button Height="48"
                Width="48"
                czb:NonClientControlProperties.HitTestResult="CLOSE"
                czb:NonClientControlProperties.ClickStrategy="AutomationPeer"
                Click="OnCloseButtonClick">
            <Button.Style>
                <Style TargetType="Button">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="Button">
                                <Grid Background="{TemplateBinding Background}">
                                    <Viewbox Height="20" Width="20">
                                        <Rectangle Fill="Blue" Height="100" Width="100">

                                        </Rectangle>
                                    </Viewbox>
                                </Grid>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsMouseOver" Value="True">
                                        <Setter Property="Background" Value="Red" />
                                    </Trigger>
                                    <Trigger Property="czb:NonClientControlProperties.IsNCMouseOver" Value="True">
                                        <Setter Property="Background" Value="Red" />
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Button.Style>
        </Button>
    </StackPanel>
</cz:WindowChromeWindow>
using ControlzEx;

namespace TestWpfApp;

public partial class MainWindow : WindowChromeWindow
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void OnCloseButtonClick(object sender, System.Windows.RoutedEventArgs e)
    {
        Close();
    }
}

Expected behavior

When I hover over the button, including the viewbox area, hover and click logic works

Actual behavior

When I hover the view box area (blue rectangle), hover and click behavior stop working:

Image

If you remove czb:NonClientControlProperties.HitTestResult="CLOSE" from the xaml letting WPF handle client area events, hovering over view box still counts as IsMouseOver, so I expect IsNCMouseOver to work the same way

Environment

- ControlzEx: 7.0.2
- Windows 10.0.19045
- .NET 10.0

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions