Windows: Ensure layouts without background participate in hit testing#34364
Windows: Ensure layouts without background participate in hit testing#34364jpd21122012 wants to merge 4 commits intodotnet:mainfrom
Conversation
On Windows, panels with a null Background do not participate in hit testing. This causes TapGestureRecognizer to not fire when layouts such as Grid or ContentView do not explicitly define a background. This change ensures that a transparent background is applied when the view background is null, allowing the element to participate in hit testing and receive gesture events. This aligns the Windows behavior with other platforms.
|
🚀 Dogfood this PR with:
curl -fsSL https://github.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 34364Or
iex "& { $(irm https://github.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 34364" |
|
Hi, just checking if this PR could be reviewed for the upcoming 10.6 servicing release. This change ensures that layouts without a background still participate in hit testing on Windows, which aligns with expected interaction behavior. The fix is minimal and scoped to input handling, without affecting public APIs, so it should be safe for servicing. Let me know if any adjustments or additional validation are needed 👍 |
kubaflo
left a comment
There was a problem hiding this comment.
Could you please review the AI's summary?
Thanks for taking a look! I reviewed the AI summary and here’s my understanding:
Regarding the points raised:
Let me know if you’d prefer that I:
|
|
If you could add a test that would be awesome |
- Verify TapGestureRecognizer works when Background is null - Ensure layouts participate in hit testing via transparent background - Add control case with explicit background to prevent regressions
Thanks! I’ve added a UITest to cover this scenario. The test verifies that layouts without a background still receive tap input by attaching a TapGestureRecognizer and asserting the result through a label update. I also included a control case with an explicit background to ensure existing behavior remains unchanged |
There was a problem hiding this comment.
Pull request overview
This PR addresses a Windows-specific hit-testing behavior where XAML Panel elements with a null background don’t participate in hit testing, preventing gesture recognizers (e.g., TapGestureRecognizer) from firing when layouts have no explicit background. The change applies a transparent background internally to ensure the platform view participates in hit testing, aligning Windows behavior with other MAUI platforms.
Changes:
- Update Windows
ViewExtensions.UpdatePlatformViewBackgroundto force a transparentPanel.Backgroundwhenview.Backgroundisnull. - Add a new HostApp issue page (
Issue32279) demonstrating tap behavior with/without explicit background. - Add an Appium UI test (
Issue32279) validating tap behavior in both scenarios.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
src/Core/src/Platform/Windows/ViewExtensions.cs |
Forces Panel to have a transparent background when MAUI background is null to enable hit testing for gestures. |
src/Controls/tests/TestCases.HostApp/Issues/Issue32279.cs |
Adds a repro page for tap gestures with/without background. |
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue32279.cs |
Adds Appium tests to validate tap gestures in both cases. |
Removed comments about "Tap target REAL" and related notes from label definitions. No functional changes were made; only code comments were cleaned up for clarity.
🚦 Gate - Test Before and After Fix📊 Expand Full Gate —
|
| Test | Without Fix (expect FAIL) | With Fix (expect PASS) |
|---|---|---|
🖥️ Issue32279 Issue32279 |
❌ PASS — 565s | ✅ PASS — 458s |
🔴 Without fix — 🖥️ Issue32279: PASS ❌ · 565s
Determining projects to restore...
Restored D:\a\1\s\src\Graphics\src\Graphics\Graphics.csproj (in 24.71 sec).
Restored D:\a\1\s\src\Graphics\src\Graphics.Win2D\Graphics.Win2D.csproj (in 24.7 sec).
Restored D:\a\1\s\src\Essentials\src\Essentials.csproj (in 7.95 sec).
Restored D:\a\1\s\src\Core\src\Core.csproj (in 16.11 sec).
Restored D:\a\1\s\src\Core\maps\src\Maps.csproj (in 14.77 sec).
Restored D:\a\1\s\src\Controls\tests\TestCases.HostApp\Controls.TestCases.HostApp.csproj (in 6.66 sec).
Restored D:\a\1\s\src\Controls\src\Xaml\Controls.Xaml.csproj (in 46 ms).
Restored D:\a\1\s\src\Controls\src\Core\Controls.Core.csproj (in 18 ms).
Restored D:\a\1\s\src\Controls\Maps\src\Controls.Maps.csproj (in 25 ms).
Restored D:\a\1\s\src\Controls\Foldable\src\Controls.Foldable.csproj (in 15 ms).
Restored D:\a\1\s\src\BlazorWebView\src\Maui\Microsoft.AspNetCore.Components.WebView.Maui.csproj (in 28 ms).
3 of 14 projects are up-to-date for restore.
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
Graphics -> D:\a\1\s\artifacts\bin\Graphics\Debug\net10.0-windows10.0.19041.0\Microsoft.Maui.Graphics.dll
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
Essentials -> D:\a\1\s\artifacts\bin\Essentials\Debug\net10.0-windows10.0.19041.0\Microsoft.Maui.Essentials.dll
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
Graphics.Win2D -> D:\a\1\s\artifacts\bin\Graphics.Win2D\Debug\net10.0-windows10.0.19041.0\Microsoft.Maui.Graphics.Win2D.WinUI.Desktop.dll
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
Core -> D:\a\1\s\artifacts\bin\Core\Debug\net10.0-windows10.0.19041.0\Microsoft.Maui.dll
Controls.BindingSourceGen -> D:\a\1\s\artifacts\bin\Controls.BindingSourceGen\Debug\netstandard2.0\Microsoft.Maui.Controls.BindingSourceGen.dll
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
Maps -> D:\a\1\s\artifacts\bin\Maps\Debug\net10.0-windows10.0.19041.0\Microsoft.Maui.Maps.dll
Controls.Core -> D:\a\1\s\artifacts\bin\Controls.Core\Debug\net10.0-windows10.0.19041.0\Microsoft.Maui.Controls.dll
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
Controls.Xaml -> D:\a\1\s\artifacts\bin\Controls.Xaml\Debug\net10.0-windows10.0.19041.0\Microsoft.Maui.Controls.Xaml.dll
Controls.Foldable -> D:\a\1\s\artifacts\bin\Controls.Foldable\Debug\net10.0-windows10.0.19041.0\Microsoft.Maui.Controls.Foldable.dll
Microsoft.AspNetCore.Components.WebView.Maui -> D:\a\1\s\artifacts\bin\Microsoft.AspNetCore.Components.WebView.Maui\Debug\net10.0-windows10.0.19041.0\Microsoft.AspNetCore.Components.WebView.Maui.dll
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
Controls.Maps -> D:\a\1\s\artifacts\bin\Controls.Maps\Debug\net10.0-windows10.0.19041.0\Microsoft.Maui.Controls.Maps.dll
Controls.TestCases.HostApp -> D:\a\1\s\artifacts\bin\Controls.TestCases.HostApp\Debug\net10.0-windows10.0.19041.0\win-x64\Controls.TestCases.HostApp.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:05:54.69
Determining projects to restore...
Restored D:\a\1\s\src\TestUtils\src\VisualTestUtils\VisualTestUtils.csproj (in 1.43 sec).
Restored D:\a\1\s\src\TestUtils\src\UITest.NUnit\UITest.NUnit.csproj (in 2.01 sec).
Restored D:\a\1\s\src\TestUtils\src\UITest.Core\UITest.Core.csproj (in 3 ms).
Restored D:\a\1\s\src\TestUtils\src\UITest.Appium\UITest.Appium.csproj (in 1.54 sec).
Restored D:\a\1\s\src\TestUtils\src\VisualTestUtils.MagickNet\VisualTestUtils.MagickNet.csproj (in 5.51 sec).
Restored D:\a\1\s\src\TestUtils\src\UITest.Analyzers\UITest.Analyzers.csproj (in 5.04 sec).
Restored D:\a\1\s\src\Controls\tests\CustomAttributes\Controls.CustomAttributes.csproj (in 15 ms).
Restored D:\a\1\s\src\Controls\tests\TestCases.WinUI.Tests\Controls.TestCases.WinUI.Tests.csproj (in 7.14 sec).
7 of 15 projects are up-to-date for restore.
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
Graphics -> D:\a\1\s\artifacts\bin\Graphics\Debug\net10.0\Microsoft.Maui.Graphics.dll
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
Essentials -> D:\a\1\s\artifacts\bin\Essentials\Debug\net10.0\Microsoft.Maui.Essentials.dll
Controls.CustomAttributes -> D:\a\1\s\artifacts\bin\Controls.CustomAttributes\Debug\net10.0\Controls.CustomAttributes.dll
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
Core -> D:\a\1\s\artifacts\bin\Core\Debug\net10.0\Microsoft.Maui.dll
Controls.Core.Design -> D:\a\1\s\artifacts\bin\Controls.Core.Design\Debug\net472\Microsoft.Maui.Controls.DesignTools.dll
Controls.BindingSourceGen -> D:\a\1\s\artifacts\bin\Controls.BindingSourceGen\Debug\netstandard2.0\Microsoft.Maui.Controls.BindingSourceGen.dll
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
Controls.Core -> D:\a\1\s\artifacts\bin\Controls.Core\Debug\net10.0\Microsoft.Maui.Controls.dll
UITest.Core -> D:\a\1\s\artifacts\bin\UITest.Core\Debug\net10.0\UITest.Core.dll
UITest.Appium -> D:\a\1\s\artifacts\bin\UITest.Appium\Debug\net10.0\UITest.Appium.dll
UITest.NUnit -> D:\a\1\s\artifacts\bin\UITest.NUnit\Debug\net10.0\UITest.NUnit.dll
VisualTestUtils -> D:\a\1\s\artifacts\bin\VisualTestUtils\Debug\netstandard2.0\VisualTestUtils.dll
VisualTestUtils.MagickNet -> D:\a\1\s\artifacts\bin\VisualTestUtils.MagickNet\Debug\netstandard2.0\VisualTestUtils.MagickNet.dll
UITest.Analyzers -> D:\a\1\s\artifacts\bin\UITest.Analyzers\Debug\netstandard2.0\UITest.Analyzers.dll
Controls.TestCases.WinUI.Tests -> D:\a\1\s\artifacts\bin\Controls.TestCases.WinUI.Tests\Debug\net10.0\Controls.TestCases.WinUI.Tests.dll
Test run for D:\a\1\s\artifacts\bin\Controls.TestCases.WinUI.Tests\Debug\net10.0\Controls.TestCases.WinUI.Tests.dll (.NETCoreApp,Version=v10.0)
VSTest version 18.0.1 (x64)
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
D:\a\1\s\artifacts\bin\Controls.TestCases.WinUI.Tests\Debug\net10.0\Controls.TestCases.WinUI.Tests.dll
NUnit Adapter 4.5.0.0: Test execution started
Running selected tests in D:\a\1\s\artifacts\bin\Controls.TestCases.WinUI.Tests\Debug\net10.0\Controls.TestCases.WinUI.Tests.dll
NUnit3TestExecutor discovered 2 of 2 NUnit test cases using Current Discovery mode, Non-Explicit run
>>>>> 4/1/2026 7:17:29 PM FixtureSetup for Issue32279(Windows)
>>>>> 4/1/2026 7:17:39 PM TapOnLayoutWithBackgroundShouldWork Start
>>>>> 4/1/2026 7:17:41 PM TapOnLayoutWithBackgroundShouldWork Stop
Passed TapOnLayoutWithBackgroundShouldWork [1 s]
>>>>> 4/1/2026 7:17:41 PM TapOnLayoutWithNoBackgroundShouldWork Start
>>>>> 4/1/2026 7:17:42 PM TapOnLayoutWithNoBackgroundShouldWork Stop
Passed TapOnLayoutWithNoBackgroundShouldWork [1 s]
NUnit Adapter 4.5.0.0: Test execution complete
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 10.0.0)
[xUnit.net 00:00:00.10] Discovering: Controls.TestCases.WinUI.Tests
[xUnit.net 00:00:00.29] Discovered: Controls.TestCases.WinUI.Tests
Test Run Successful.
Total tests: 2
Passed: 2
Total time: 33.2720 Seconds
🟢 With fix — 🖥️ Issue32279: PASS ✅ · 458s
Determining projects to restore...
All projects are up-to-date for restore.
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
Graphics -> D:\a\1\s\artifacts\bin\Graphics\Debug\net10.0-windows10.0.19041.0\Microsoft.Maui.Graphics.dll
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
Graphics.Win2D -> D:\a\1\s\artifacts\bin\Graphics.Win2D\Debug\net10.0-windows10.0.19041.0\Microsoft.Maui.Graphics.Win2D.WinUI.Desktop.dll
Essentials -> D:\a\1\s\artifacts\bin\Essentials\Debug\net10.0-windows10.0.19041.0\Microsoft.Maui.Essentials.dll
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
Core -> D:\a\1\s\artifacts\bin\Core\Debug\net10.0-windows10.0.19041.0\Microsoft.Maui.dll
Controls.BindingSourceGen -> D:\a\1\s\artifacts\bin\Controls.BindingSourceGen\Debug\netstandard2.0\Microsoft.Maui.Controls.BindingSourceGen.dll
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
Controls.Core -> D:\a\1\s\artifacts\bin\Controls.Core\Debug\net10.0-windows10.0.19041.0\Microsoft.Maui.Controls.dll
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
Controls.Foldable -> D:\a\1\s\artifacts\bin\Controls.Foldable\Debug\net10.0-windows10.0.19041.0\Microsoft.Maui.Controls.Foldable.dll
Microsoft.AspNetCore.Components.WebView.Maui -> D:\a\1\s\artifacts\bin\Microsoft.AspNetCore.Components.WebView.Maui\Debug\net10.0-windows10.0.19041.0\Microsoft.AspNetCore.Components.WebView.Maui.dll
Maps -> D:\a\1\s\artifacts\bin\Maps\Debug\net10.0-windows10.0.19041.0\Microsoft.Maui.Maps.dll
Controls.Xaml -> D:\a\1\s\artifacts\bin\Controls.Xaml\Debug\net10.0-windows10.0.19041.0\Microsoft.Maui.Controls.Xaml.dll
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
Controls.Maps -> D:\a\1\s\artifacts\bin\Controls.Maps\Debug\net10.0-windows10.0.19041.0\Microsoft.Maui.Controls.Maps.dll
Controls.TestCases.HostApp -> D:\a\1\s\artifacts\bin\Controls.TestCases.HostApp\Debug\net10.0-windows10.0.19041.0\win-x64\Controls.TestCases.HostApp.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:05:39.42
Determining projects to restore...
All projects are up-to-date for restore.
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
Graphics -> D:\a\1\s\artifacts\bin\Graphics\Debug\net10.0\Microsoft.Maui.Graphics.dll
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
Essentials -> D:\a\1\s\artifacts\bin\Essentials\Debug\net10.0\Microsoft.Maui.Essentials.dll
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
Core -> D:\a\1\s\artifacts\bin\Core\Debug\net10.0\Microsoft.Maui.dll
Controls.CustomAttributes -> D:\a\1\s\artifacts\bin\Controls.CustomAttributes\Debug\net10.0\Controls.CustomAttributes.dll
Controls.Core.Design -> D:\a\1\s\artifacts\bin\Controls.Core.Design\Debug\net472\Microsoft.Maui.Controls.DesignTools.dll
Controls.BindingSourceGen -> D:\a\1\s\artifacts\bin\Controls.BindingSourceGen\Debug\netstandard2.0\Microsoft.Maui.Controls.BindingSourceGen.dll
##vso[build.updatebuildnumber]10.0.60-ci+azdo.13715269
Controls.Core -> D:\a\1\s\artifacts\bin\Controls.Core\Debug\net10.0\Microsoft.Maui.Controls.dll
UITest.Core -> D:\a\1\s\artifacts\bin\UITest.Core\Debug\net10.0\UITest.Core.dll
UITest.Appium -> D:\a\1\s\artifacts\bin\UITest.Appium\Debug\net10.0\UITest.Appium.dll
UITest.NUnit -> D:\a\1\s\artifacts\bin\UITest.NUnit\Debug\net10.0\UITest.NUnit.dll
VisualTestUtils -> D:\a\1\s\artifacts\bin\VisualTestUtils\Debug\netstandard2.0\VisualTestUtils.dll
VisualTestUtils.MagickNet -> D:\a\1\s\artifacts\bin\VisualTestUtils.MagickNet\Debug\netstandard2.0\VisualTestUtils.MagickNet.dll
UITest.Analyzers -> D:\a\1\s\artifacts\bin\UITest.Analyzers\Debug\netstandard2.0\UITest.Analyzers.dll
Controls.TestCases.WinUI.Tests -> D:\a\1\s\artifacts\bin\Controls.TestCases.WinUI.Tests\Debug\net10.0\Controls.TestCases.WinUI.Tests.dll
Test run for D:\a\1\s\artifacts\bin\Controls.TestCases.WinUI.Tests\Debug\net10.0\Controls.TestCases.WinUI.Tests.dll (.NETCoreApp,Version=v10.0)
VSTest version 18.0.1 (x64)
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
D:\a\1\s\artifacts\bin\Controls.TestCases.WinUI.Tests\Debug\net10.0\Controls.TestCases.WinUI.Tests.dll
NUnit Adapter 4.5.0.0: Test execution started
Running selected tests in D:\a\1\s\artifacts\bin\Controls.TestCases.WinUI.Tests\Debug\net10.0\Controls.TestCases.WinUI.Tests.dll
NUnit3TestExecutor discovered 2 of 2 NUnit test cases using Current Discovery mode, Non-Explicit run
>>>>> 4/1/2026 7:25:08 PM FixtureSetup for Issue32279(Windows)
>>>>> 4/1/2026 7:25:17 PM TapOnLayoutWithBackgroundShouldWork Start
>>>>> 4/1/2026 7:25:19 PM TapOnLayoutWithBackgroundShouldWork Stop
Passed TapOnLayoutWithBackgroundShouldWork [1 s]
>>>>> 4/1/2026 7:25:19 PM TapOnLayoutWithNoBackgroundShouldWork Start
>>>>> 4/1/2026 7:25:20 PM TapOnLayoutWithNoBackgroundShouldWork Stop
Passed TapOnLayoutWithNoBackgroundShouldWork [1 s]
NUnit Adapter 4.5.0.0: Test execution complete
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 10.0.0)
[xUnit.net 00:00:00.11] Discovering: Controls.TestCases.WinUI.Tests
[xUnit.net 00:00:00.31] Discovered: Controls.TestCases.WinUI.Tests
Test Run Successful.
Total tests: 2
Passed: 2
Total time: 26.9199 Seconds
⚠️ Issues found
- ❌ Issue32279 PASSED without fix (should fail) — tests don't catch the bug
📁 Fix files reverted (2 files)
eng/pipelines/ci-copilot.ymlsrc/Core/src/Platform/Windows/ViewExtensions.cs
🤖 AI Summary📊 Expand Full Review —
|
| # | Source | Approach | Test Result | Files Changed | Notes |
|---|---|---|---|---|---|
| PR | PR #34364 | After panel.UpdateBackground(), if view.Background == null set panel.Background = transparent |
❌ Gate FAILED | ViewExtensions.cs, Issue32279.cs (HostApp), Issue32279.cs (Tests) |
Test uses Grid not ContentView; Grid already works via LayoutPanel's mechanism |
🔧 Fix — Analysis & Comparison
Fix Candidates
| # | Source | Approach | Test Result | Files Changed | Notes |
|---|---|---|---|---|---|
| 1 | try-fix (claude-opus-4.6) | ContentPanel self-healing background via DependencyProperty callback in constructor; also fixed test to use ContentView | PASS | ContentPanel.cs, Issue32279.cs (HostApp) |
Fixes at class level; requires guard flag to prevent recursion |
| 2 | try-fix (claude-sonnet-4.6) | ContentPanel-specific else if branch in ViewExtensions.UpdatePlatformViewBackground before generic Panel; test fixed to ContentView |
PASS | ViewExtensions.cs, Issue32279.cs (HostApp) |
Targeted, clear, does not change ContentPanel internals |
| 3 | try-fix (gpt-5.3-codex) | Modified ContentPanel.UpdateBackground(Paint?) to also set Panel.Background=transparent when background is null; test fixed to ContentView |
PASS | ContentPanel.cs, Issue32279.cs (HostApp) |
Co-located with existing background logic in ContentPanel |
| 4 | try-fix (gpt-5.4) | PR approach with reviewer guard: view.Background == null && panel.Background == null in ViewExtensions; test fixed to ContentView |
PASS | ViewExtensions.cs, Issue32279.cs (HostApp) |
Minimal delta from PR; applies to all Panel types with safety guard |
| PR | PR #34364 | In ViewExtensions after UpdateBackground, if (view.Background == null) set panel.Background=transparent |
Gate FAILED | ViewExtensions.cs, Issue32279.cs (HostApp+Tests) |
Test uses Grid not ContentView; Grid already worked via LayoutPanel.MakeInputVisible |
Cross-Pollination
| Model | Round | New Ideas? | Details |
|---|---|---|---|
| claude-opus-4.6 | 2 | No | NO NEW IDEAS all fix insertion points covered |
Exhausted: Yes
Selected Fix: Candidate #2 (claude-sonnet-4.6) ContentPanel-specific branch in ViewExtensions
Reason: Most targeted approach applies only to ContentPanel without modifying ContentPanel internals. Explicit else if (platformView is ContentPanel) branch before the generic Panel branch is readable and follows the existing if/else chain pattern. Does not affect LayoutPanel (which already handles null background correctly via MakeInputVisible). Simpler than Attempt 1 (no DependencyProperty callback complexity), more focused than Attempt 4 (which applies to all Panel types). All candidates also fix the test to use ContentView which is the actual failing case.
📋 Report — Final Recommendation
Final Recommendation: REQUEST CHANGES
Phase Status
| Phase | Status | Notes |
|---|---|---|
| Pre-Flight | COMPLETE | Issue #32279, Windows-only, ContentView/ContentPanel hit testing |
| Gate | FAILED | windows tests did not behave as expected |
| Try-Fix | COMPLETE | 4 attempts, all 4 passing |
| Report | COMPLETE |
Summary
PR #34364 fixes a real bug where TapGestureRecognizer does not fire on Windows layouts (ContentView, Grid, etc.) that have no explicit background. The root cause is correct and the implementation direction is sound, but two issues need to be addressed before merge: (1) the test exercises Grid instead of ContentView, which was the reported failing case Grid already worked before the fix via LayoutPanel.MakeInputVisible(), so the gate failed because the test passed even on broken baseline; (2) the implementation check if (view.Background == null) applies the transparent brush to all Panel types without guarding whether the panel already has a non-null background, potentially conflicting with styles/templates.
Root Cause
WinUI Panel with Background = null does not participate in pointer hit testing. ContentPanel (the Windows platform view for ContentView) inherits from Panel and its UpdateBackground(Paint?) method only updates the _borderPath visual rendering it does not set Panel.Background. As a result, ContentPanel.Background remains null when the MAUI view has no background, causing all pointer events (including gestures) to pass through.
LayoutPanel (used for Grid, StackLayout etc.) already solves this via MakeInputVisible() which sets a transparent brush when background is null. ContentPanel had no equivalent mechanism.
Fix Quality
PR's fix: Adds if (view.Background == null) panel.Background = transparent in ViewExtensions.UpdatePlatformViewBackground(FrameworkElement, IView) after panel.UpdateBackground(). Issues:
- No guard on
panel.Backgroundmay overwrite non-null backgrounds set by styles, allocates a new brush on every call even when background was already set - Test uses
Grid(LayoutPanel) which already handled null backgrounds gate fails because test passes on broken baseline
Better fix (Candidate #2 found via Try-Fix): Add a ContentPanel-specific else if branch in ViewExtensions.UpdatePlatformViewBackground before the generic Panel branch. This:
- Targets only
ContentPanel, not allPaneltypes - Sets
contentPanel.Backgroundto transparent when MAUI background is null (mirrors the LayoutPanel/MakeInputVisible pattern) - Is explicit and easy to understand
- Requires fixing the test to use
ContentView(notGrid) to actually exercise the ContentPanel code path
Required changes:
src/Core/src/Platform/Windows/ViewExtensions.cs: Replace the currentPanelbranch approach with a dedicatedContentPanel-specific branchsrc/Controls/tests/TestCases.HostApp/Issues/Issue32279.cs: ChangeGridtoContentViewfor the no-background case (and optionally keep aGridcase for broader coverage)
…Panel - Update UITest to use ContentView instead of Grid - Scope transparent background fallback to ContentPanel only - Add guard to avoid overriding existing backgrounds
Thanks for the feedback! I’ve updated the test to use ContentView so it now exercises the ContentPanel code path, which matches the original issue scenario. I also scoped the fix specifically to ContentPanel and added a guard to avoid overriding existing platform backgrounds. Both tests now fail without the fix and pass with it locally |
On Windows, panels with a null Background do not participate in hit testing.
This causes TapGestureRecognizer to not fire when layouts such as Grid, ContentView, or other panels do not explicitly define a background.
As a result, tapping on elements without a background does not trigger gesture recognizers, even though the same scenario works correctly on other platforms.
This change ensures that when a layout's background is null, a transparent background is applied internally so the element participates in hit testing. This allows gesture recognizers such as TapGestureRecognizer to function correctly without requiring developers to explicitly set a background.
The behavior now aligns with other MAUI platforms where layouts without backgrounds can still receive gestures.
Changes
Ensures Panel elements on Windows receive a transparent background when view.Background is null.
This allows layouts without explicit backgrounds to participate in hit testing and receive gesture events.
Tested scenarios
Verified using a simple repro:
Grid
└ ContentView
└ TapGestureRecognizer
Case A
Grid with background → Tap works.
Case B
ContentView with background → Tap works.
Case C
No background defined → Tap now works correctly.
Issue
Fixes #32279