1+ #if WINDOWS
2+ using System . Runtime . InteropServices ;
3+ #endif
4+
5+ namespace Maui . Controls . Sample . Issues ;
6+
7+ [ Issue ( IssueTracker . Github , 30536 , "[Windows] PointerGestureRecognizer behaves incorrectly when multiple windows are open" , PlatformAffected . UWP ) ]
8+ public class Issue30536 : ContentPage
9+ {
10+ Button newWindowButton ;
11+ Button closeNewWindowButton ;
12+ Button minimizeSecondWindowButton ;
13+ Label pointerEnterCountLabel ;
14+ Label pointerExitCountLabel ;
15+ Border theBorder ;
16+ int enterCount = 0 ;
17+ int exitCount = 0 ;
18+ Window secondWindow ;
19+ public Issue30536 ( )
20+ {
21+ InitializeUI ( ) ;
22+ }
23+
24+ private void InitializeUI ( )
25+ {
26+ // Create the VerticalStackLayout
27+ var stackLayout = new VerticalStackLayout
28+ {
29+ Spacing = 5
30+ } ;
31+
32+ // Create New Window button
33+ newWindowButton = new Button
34+ {
35+ Text = "New Window" ,
36+ AutomationId = "NewWindowButton"
37+ } ;
38+ newWindowButton . Clicked += OnNewWindowButton_Clicked ;
39+
40+ closeNewWindowButton = new Button
41+ {
42+ Text = "Close New Window" ,
43+ AutomationId = "CloseNewWindowButton"
44+ } ;
45+ closeNewWindowButton . Clicked += ( sender , e ) =>
46+ {
47+ if ( secondWindow != null )
48+ {
49+ Application . Current . CloseWindow ( secondWindow ) ;
50+ secondWindow = null ;
51+ }
52+ } ;
53+
54+ minimizeSecondWindowButton = new Button
55+ {
56+ Text = "Minimize Second Window" ,
57+ AutomationId = "MinimizeSecondWindowButton"
58+ } ;
59+ minimizeSecondWindowButton . Clicked += ( sender , e ) =>
60+ {
61+ if ( secondWindow != null )
62+ {
63+ MinimizeWindow ( secondWindow ) ;
64+ }
65+ } ;
66+
67+ // Create pointer enter count label
68+ pointerEnterCountLabel = new Label
69+ {
70+ Text = $ "Pointer Enter Count: { enterCount } ",
71+ AutomationId = "PointerEnterCountLabel"
72+
73+ } ;
74+
75+ pointerExitCountLabel = new Label
76+ {
77+ Text = $ "Pointer Exit Count: { exitCount } ",
78+ AutomationId = "PointerExitCountLabel"
79+
80+ } ;
81+
82+ // Create the border with red background
83+ theBorder = new Border
84+ {
85+ WidthRequest = 500 ,
86+ HeightRequest = 500 ,
87+ BackgroundColor = Colors . Red ,
88+ Content = new Button
89+ {
90+ Text = "Tap Me" ,
91+ AutomationId = "BorderButton"
92+ }
93+ } ;
94+
95+ // Create and add PointerGestureRecognizer
96+ var pointerGestureRecognizer = new PointerGestureRecognizer ( ) ;
97+ pointerGestureRecognizer . PointerEntered += OnPointerGestureRecognizer_PointerEntered ;
98+ pointerGestureRecognizer . PointerExited += OnPointerGestureRecognizer_PointerExited ;
99+ theBorder . GestureRecognizers . Add ( pointerGestureRecognizer ) ;
100+
101+ // Add all elements to the stack layout
102+ stackLayout . Children . Add ( minimizeSecondWindowButton ) ;
103+ stackLayout . Children . Add ( newWindowButton ) ;
104+ stackLayout . Children . Add ( closeNewWindowButton ) ;
105+ stackLayout . Children . Add ( pointerEnterCountLabel ) ;
106+ stackLayout . Children . Add ( pointerExitCountLabel ) ;
107+ stackLayout . Children . Add ( theBorder ) ;
108+
109+ // Set the content
110+ Content = stackLayout ;
111+ }
112+
113+ #if WINDOWS
114+ // Windows API declarations
115+ [ DllImport ( "user32.dll" ) ]
116+ private static extern bool ShowWindow ( IntPtr hWnd , int nCmdShow ) ;
117+
118+ // ShowWindow constants
119+ private const int SW_MINIMIZE = 6 ;
120+ #endif
121+
122+ private void OnNewWindowButton_Clicked ( object sender , EventArgs e )
123+ {
124+ secondWindow = new Window ( new ContentPage ( ) ) ;
125+ Application . Current . OpenWindow ( secondWindow ) ;
126+ }
127+
128+ private void MinimizeWindow ( Window window )
129+ {
130+ #if WINDOWS
131+ if ( window . Handler ? . PlatformView is Microsoft . UI . Xaml . Window win )
132+ {
133+ // Get window handle directly from MAUI's platform view
134+ var hwnd = WinRT . Interop . WindowNative . GetWindowHandle ( win ) ;
135+ if ( hwnd != IntPtr . Zero )
136+ {
137+ ShowWindow ( hwnd , SW_MINIMIZE ) ;
138+ }
139+ }
140+ #endif
141+ }
142+ private void OnPointerGestureRecognizer_PointerEntered ( object sender , PointerEventArgs e )
143+ {
144+ theBorder . BackgroundColor = Colors . Lime ;
145+ enterCount ++ ;
146+ pointerEnterCountLabel . Text = $ "Pointer Enter Count: { enterCount } ";
147+ }
148+ private void OnPointerGestureRecognizer_PointerExited ( object sender , PointerEventArgs e )
149+ {
150+ theBorder . BackgroundColor = Colors . Red ;
151+ exitCount ++ ;
152+ pointerExitCountLabel . Text = $ "Pointer Exit Count: { exitCount } ";
153+ }
154+ }
0 commit comments