Skip to content

Windows: Ensure layouts without background participate in hit testing#34364

Open
jpd21122012 wants to merge 4 commits intodotnet:mainfrom
jpd21122012:fix/32279-TapGestureRecognizer-NoBackground-Windows
Open

Windows: Ensure layouts without background participate in hit testing#34364
jpd21122012 wants to merge 4 commits intodotnet:mainfrom
jpd21122012:fix/32279-TapGestureRecognizer-NoBackground-Windows

Conversation

@jpd21122012
Copy link
Copy Markdown
Contributor

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

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.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 7, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://github.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 34364

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://github.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 34364"

@jpd21122012
Copy link
Copy Markdown
Contributor Author

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 👍

@MauiBot MauiBot added s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-gate-failed AI could not verify tests catch the bug s/agent-fix-win AI found a better alternative fix than the PR s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review) labels Mar 22, 2026
Copy link
Copy Markdown
Contributor

@kubaflo kubaflo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please review the AI's summary?

@jpd21122012
Copy link
Copy Markdown
Contributor Author

Could you please review the AI's summary?

Thanks for taking a look!

I reviewed the AI summary and here’s my understanding:

  • The core issue is that, on Windows, layouts without a background do not participate in hit testing, which prevents gesture recognizers from working as expected.
  • The current fix ensures a transparent background is applied when the MAUI background is null, allowing the layout to participate in hit testing consistently.

Regarding the points raised:

  • Test coverage: I agree that adding a regression test would be valuable, and I can work on adding one for this scenario.
  • Scope of the fix: The current approach applies a general solution to ensure consistent behavior across layouts. I chose this to keep the fix simple and reliable, without introducing gesture-specific conditions that could add complexity or edge cases.
  • The alternative (gesture-scoped fallback) could be explored, but it would require more targeted logic and potentially more maintenance overhead.

Let me know if you’d prefer that I:

  1. Add test coverage only, or
  2. Also refine the fix to be more narrowly scoped

@kubaflo
Copy link
Copy Markdown
Contributor

kubaflo commented Mar 23, 2026

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
Copilot AI review requested due to automatic review settings March 23, 2026 17:37
@jpd21122012
Copy link
Copy Markdown
Contributor Author

If you could add a test that would be awesome

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.UpdatePlatformViewBackground to force a transparent Panel.Background when view.Background is null.
  • 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.

Comment thread src/Core/src/Platform/Windows/ViewExtensions.cs Outdated
Comment thread src/Controls/tests/TestCases.HostApp/Issues/Issue32279.cs Outdated
Comment thread src/Controls/tests/TestCases.HostApp/Issues/Issue32279.cs Outdated
Comment thread src/Controls/tests/TestCases.HostApp/Issues/Issue32279.cs Outdated
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.
@MauiBot MauiBot added s/agent-review-incomplete AI agent could not complete all phases (blocker, timeout, error) and removed s/agent-changes-requested AI agent recommends changes - found a better alternative or issues labels Mar 24, 2026
@jpd21122012 jpd21122012 requested a review from kubaflo April 1, 2026 17:18
@dotnet dotnet deleted a comment from MauiBot Apr 1, 2026
@MauiBot
Copy link
Copy Markdown
Collaborator

MauiBot commented Apr 1, 2026

🚦 Gate - Test Before and After Fix

📊 Expand Full Gatebc6627c · Remove tap target explanatory comments from labels

Gate Result: ❌ FAILED

Platform: WINDOWS · Base: main · Merge base: 720a9d4a

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.yml
  • src/Core/src/Platform/Windows/ViewExtensions.cs

@MauiBot
Copy link
Copy Markdown
Collaborator

MauiBot commented Apr 1, 2026

🤖 AI Summary

📊 Expand Full Reviewbc6627c · Remove tap target explanatory comments from labels
🔍 Pre-Flight — Context & Validation

Issue: #32279 - [Windows] TapGestureRecognizer does NOT work on a ContentView without Background
PR: #34364 - Windows: Ensure layouts without background participate in hit testing
Platforms Affected: Windows only
Files Changed: 1 implementation, 2 test

Key Findings

  • On Windows, a WinUI Panel with Background = null does not participate in hit testing — taps fall through
  • The issue originally reported for ContentView (mapped to ContentPanel which extends Panel) but affects all Panel-based views
  • LayoutPanel (used for MAUI Grid/StackLayout) already handles this correctly via MakeInputVisible() in LayoutPanel.cs:64-71 — Grid tests likely pass regardless of the fix
  • The PR's fix is in UpdatePlatformViewBackground(FrameworkElement, IView): after calling panel.UpdateBackground(view.Background), if view.Background == null, sets panel.Background = transparent
  • Test gap: HostApp test page uses Grid (not ContentView), so it does not exercise the actual ContentPanel/ContentView code path that the issue reports — this is likely why Gate FAILED (tests pass even without the fix, since Grid already worked)
  • A previous Copilot review flagged: (a) the fix should also check panel.Background == null after UpdateBackground, and (b) test should use ContentView not Grid
  • The fix condition view.Background == null (without also checking panel.Background) may set transparent brush unnecessarily even when UpdateBackground has already set a non-null background from styles/templates

Fix Candidates

# 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.Background may 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 all Panel types
  • Sets contentPanel.Background to transparent when MAUI background is null (mirrors the LayoutPanel/MakeInputVisible pattern)
  • Is explicit and easy to understand
  • Requires fixing the test to use ContentView (not Grid) to actually exercise the ContentPanel code path

Required changes:

  1. src/Core/src/Platform/Windows/ViewExtensions.cs: Replace the current Panel branch approach with a dedicated ContentPanel-specific branch
  2. src/Controls/tests/TestCases.HostApp/Issues/Issue32279.cs: Change Grid to ContentView for the no-background case (and optionally keep a Grid case for broader coverage)

@MauiBot MauiBot added s/agent-changes-requested AI agent recommends changes - found a better alternative or issues and removed s/agent-review-incomplete AI agent could not complete all phases (blocker, timeout, error) labels Apr 1, 2026
…Panel

- Update UITest to use ContentView instead of Grid
- Scope transparent background fallback to ContentPanel only
- Add guard to avoid overriding existing backgrounds
@jpd21122012
Copy link
Copy Markdown
Contributor Author

🤖 AI Summary

📊 Expand Full Reviewbc6627c · Remove tap target explanatory comments from labels

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-gestures Gesture types community ✨ Community Contribution platform/windows s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-fix-win AI found a better alternative fix than the PR s/agent-gate-failed AI could not verify tests catch the bug s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Windows] TapGestureRecognizer does NOT work on a ContentView without Background

5 participants