From 771710b35e9c817e45aeb4243ba358864f2cb8e7 Mon Sep 17 00:00:00 2001 From: xylieong <61135607+xylieong@users.noreply.github.com> Date: Thu, 27 Feb 2025 09:40:07 +0800 Subject: [PATCH 1/4] TitleBar Header or TrailingContent UIElement if IsHitVisible set false, then user is not able to click on the UIElement. When TitleBar is customised with TextBlock only and with IsHitVisible set false, then allow user to click on the TextBlock and able to select & move the window. --- src/Wpf.Ui/Extensions/UiElementExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Wpf.Ui/Extensions/UiElementExtensions.cs b/src/Wpf.Ui/Extensions/UiElementExtensions.cs index 164c54e3a..39e1a718e 100644 --- a/src/Wpf.Ui/Extensions/UiElementExtensions.cs +++ b/src/Wpf.Ui/Extensions/UiElementExtensions.cs @@ -26,7 +26,7 @@ public static bool IsMouseOverElement(this UIElement element, IntPtr lParam) Point mousePosRelative = element.PointFromScreen(mousePosScreen); - return bounds.Contains(mousePosRelative); + return bounds.Contains(mousePosRelative) && element.IsHitTestVisible; } catch { From fa3cd175a274398c3ebfcd2fe39448a80fa0ad44 Mon Sep 17 00:00:00 2001 From: xylieong <61135607+xylieong@users.noreply.github.com> Date: Thu, 27 Feb 2025 10:53:42 +0800 Subject: [PATCH 2/4] Added 2 layers of checking for IsHitTestVisible if UIElement is Panel --- src/Wpf.Ui/Extensions/UiElementExtensions.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Wpf.Ui/Extensions/UiElementExtensions.cs b/src/Wpf.Ui/Extensions/UiElementExtensions.cs index 39e1a718e..75ce55028 100644 --- a/src/Wpf.Ui/Extensions/UiElementExtensions.cs +++ b/src/Wpf.Ui/Extensions/UiElementExtensions.cs @@ -25,6 +25,16 @@ public static bool IsMouseOverElement(this UIElement element, IntPtr lParam) var bounds = new Rect(default, element.RenderSize); Point mousePosRelative = element.PointFromScreen(mousePosScreen); + if (bounds.Contains(mousePosRelative) && element.IsHitTestVisible && element is Panel) + { + foreach (UIElement child in (element as Panel).Children) + { + if (new Rect(default, element.RenderSize).Contains(mousePosRelative)) + { + return child.IsHitTestVisible; + } + } + } return bounds.Contains(mousePosRelative) && element.IsHitTestVisible; } From 150a2433d1e2f6363fc7a083317edefa9dba1eb5 Mon Sep 17 00:00:00 2001 From: xylieong <61135607+xylieong@users.noreply.github.com> Date: Mon, 3 Mar 2025 08:31:50 +0800 Subject: [PATCH 3/4] Simplified & Optimised code --- src/Wpf.Ui/Extensions/UiElementExtensions.cs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/Wpf.Ui/Extensions/UiElementExtensions.cs b/src/Wpf.Ui/Extensions/UiElementExtensions.cs index 75ce55028..01a1f2316 100644 --- a/src/Wpf.Ui/Extensions/UiElementExtensions.cs +++ b/src/Wpf.Ui/Extensions/UiElementExtensions.cs @@ -23,20 +23,13 @@ public static bool IsMouseOverElement(this UIElement element, IntPtr lParam) { var mousePosScreen = new Point(Get_X_LParam(lParam), Get_Y_LParam(lParam)); var bounds = new Rect(default, element.RenderSize); - Point mousePosRelative = element.PointFromScreen(mousePosScreen); - if (bounds.Contains(mousePosRelative) && element.IsHitTestVisible && element is Panel) - { - foreach (UIElement child in (element as Panel).Children) - { - if (new Rect(default, element.RenderSize).Contains(mousePosRelative)) - { - return child.IsHitTestVisible; - } - } - } - - return bounds.Contains(mousePosRelative) && element.IsHitTestVisible; + + return bounds.Contains(mousePosRelative) && element.IsHitTestVisible && + (!(element is System.Windows.Controls.Panel) || // If element is Panel, check if children at mousePosRelative is with IsHitTestVisible false. + (((System.Windows.Controls.Panel)element).Children.OfType() + .FirstOrDefault(child => new Rect(default, child.RenderSize).Contains(mousePosRelative)) + ?.IsHitTestVisible ?? false)); } catch { From 1f30162ede4f4c2b5c09ab26038ef484f9485f9d Mon Sep 17 00:00:00 2001 From: xylieong <61135607+xylieong@users.noreply.github.com> Date: Mon, 3 Mar 2025 09:00:26 +0800 Subject: [PATCH 4/4] Updated TitleBar.xaml, removed IsHitTestVisible for MaximizeButton --- src/Wpf.Ui/Controls/TitleBar/TitleBar.xaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Wpf.Ui/Controls/TitleBar/TitleBar.xaml b/src/Wpf.Ui/Controls/TitleBar/TitleBar.xaml index 9dddd9b1c..e285a6e92 100644 --- a/src/Wpf.Ui/Controls/TitleBar/TitleBar.xaml +++ b/src/Wpf.Ui/Controls/TitleBar/TitleBar.xaml @@ -176,8 +176,7 @@ + ButtonType="Maximize" />