Skip to content

[Windows] Fix TitleBar.IsVisible = false the caption buttons become unresponsive#33256

Merged
PureWeen merged 7 commits intodotnet:inflight/currentfrom
devanathan-vaithiyanathan:fix-33171
Jan 27, 2026
Merged

[Windows] Fix TitleBar.IsVisible = false the caption buttons become unresponsive#33256
PureWeen merged 7 commits intodotnet:inflight/currentfrom
devanathan-vaithiyanathan:fix-33171

Conversation

@devanathan-vaithiyanathan
Copy link
Contributor

Issue Details

On Windows, when TitleBar.IsVisible is set to false, the system caption buttons (minimize, maximize, close) become unresponsive after resizing the window.

Description of Change

Updated WindowRootView.UpdateTitleBarContentSize() to apply passthrough regions only when the TitleBar is visible and to clear them when it is hidden, preventing stale regions from blocking caption button interactions.

Issues Fixed

Fixes #33171

Tested the behavior in the following platforms.

  • Android
  • Windows
  • iOS
  • Mac
Before After
Windows
After.mov
Windows
Before.mov

@sheiksyedm
Copy link
Contributor

/rebase

Copy link
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 pull request fixes a Windows-specific issue where system caption buttons (minimize, maximize, close) become unresponsive after resizing the window when TitleBar.IsVisible is set to false.

Key Changes

  • Updated WindowRootView.UpdateTitleBarContentSize() to conditionally apply passthrough regions based on TitleBar visibility
  • Added Windows-specific UI test helper methods to interact with system caption buttons via Appium
  • Created comprehensive UI test to verify caption button responsiveness when TitleBar is hidden

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/Core/src/Platform/Windows/WindowRootView.cs Added visibility check to only set passthrough regions when TitleBar is visible, and clear them when hidden to prevent blocking caption buttons
src/TestUtils/src/UITest.Appium/HelperExtensions.cs Added TapMinimizeButton(), TapMaximizeButton(), and FindSystemButton() helper methods for Windows UI automation testing of system caption buttons
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue33171.cs Created Windows-specific NUnit test that verifies caption buttons remain responsive when TitleBar visibility is toggled and window is resized
src/Controls/tests/TestCases.HostApp/Issues/Issue33171.cs Created test page with TitleBar, visibility toggle button, window resize button, and window size label to reproduce and test the issue

Comment on lines +16 to +26
public void TitleBarCaptionButtonsResponsiveWhenIsVisibleFalse()
{
App.WaitForElement("ToggleTitleBarVisibilityButton");
App.Tap("ToggleTitleBarVisibilityButton");
App.Tap("ReduceWidthButton");
var windowSize = App.FindElement("WindowSizeLabel").GetText();
App.TapMaximizeButton();
App.Tap("GetStatusButton");
var newWindowSize = App.FindElement("WindowSizeLabel").GetText();
Assert.That(newWindowSize, Is.Not.EqualTo(windowSize), "Window size should change after maximizing the window.");
}
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

The test verifies that the maximize button works after toggling TitleBar visibility and reducing window width. However, the PR description states that caption buttons become unresponsive "after resizing the window". The test should verify this specific scenario by:

  1. Setting TitleBar.IsVisible = false
  2. Resizing the window (currently done via ReduceWidthButton)
  3. Attempting to click caption buttons to verify they are responsive

The current test flow doesn't clearly demonstrate the bug scenario described in the PR - it toggles visibility, reduces width, maximizes, and checks the size change. Consider adding a more explicit test that demonstrates caption buttons are responsive after window resize with TitleBar.IsVisible = false.

Copilot uses AI. Check for mistakes.
@jeremy-visionaid
Copy link
Contributor

LGTM, thanks!

@sheiksyedm
Copy link
Contributor

/rebase

@PureWeen
Copy link
Member

/rebase

@PureWeen
Copy link
Member

Code Review - Suggested Simplifications

After testing multiple alternative approaches and having 4 different AI models evaluate the implementation, all models unanimously identified two optimization opportunities in the current fix.

✅ Current Implementation: CORRECT

The fix successfully solves the caption button responsiveness issue. However, it can be simplified for better performance and clarity.


🔴 Issue #1: Duplicate Visibility Check

Current code checks visibility twice:

  • Line 204: AppTitleBarContentControl.Visibility == UI.Xaml.Visibility.Visible
  • Line 234: AppTitleBarContentControl.Visibility == UI.Xaml.Visibility.Visible

Suggested: Cache the visibility check once at the start:

bool isTitleBarVisible = AppTitleBarContentControl.Visibility == UI.Xaml.Visibility.Visible;

🔴 Issue #2: Unnecessary Loop Execution (Performance)

Current code (lines 217-225) always executes the loop even when title bar is hidden:

The code performs expensive TransformToVisual() calculations, then checks visibility afterward and discards the results if hidden.

Suggested: Gate the loop behind the visibility check:

if (isTitleBarVisible && PassthroughTitlebarElements.Count > 0)
{
    // Only calculate rects when actually needed
    var rectArray = new List<Rect32>();
    foreach (var child in PassthroughTitlebarElements)
    {
        // ... expensive calculations ...
    }
    nonClientInputSrc.SetRegionRects(...);
}
else
{
    nonClientInputSrc.ClearRegionRects(...);
}

💡 Recommended Refactor

Click to see full optimized implementation
internal void UpdateTitleBarContentSize()
{
    if (AppTitleBarContentControl is null)
        return;

    // Cache visibility check (fixes issue #1)
    bool isTitleBarVisible = AppTitleBarContentControl.Visibility == UI.Xaml.Visibility.Visible;

    // Update height logic
    if (isTitleBarVisible && _appTitleBarHeight != AppTitleBarContentControl.ActualHeight)
    {
        UpdateRootNavigationViewMargins(AppTitleBarContentControl.ActualHeight);

        if (AppWindowId.HasValue)
        {
            AppWindow.GetFromWindowId(AppWindowId.Value).TitleBar.PreferredHeightOption =
                _appTitleBarHeight >= 48 ? TitleBarHeightOption.Tall : TitleBarHeightOption.Standard;
        }

        this.RefreshThemeResources();
    }

    // Update passthrough regions
    if (AppWindowId.HasValue)
    {
        var nonClientInputSrc = InputNonClientPointerSource.GetForWindowId(AppWindowId.Value);

        // Only calculate rects when needed (fixes issue #2)
        if (isTitleBarVisible && PassthroughTitlebarElements.Count > 0)
        {
            var rectArray = new List<Rect32>();
            foreach (var child in PassthroughTitlebarElements)
            {
                var transform = child.TransformToVisual(null);
                var bounds = transform.TransformBounds(
                    new FRect(0, 0, child.ActualWidth, child.ActualHeight));
                rectArray.Add(GetRect(bounds, XamlRoot.RasterizationScale));
            }

            nonClientInputSrc.SetRegionRects(NonClientRegionKind.Passthrough, [.. rectArray]);
        }
        else
        {
            nonClientInputSrc.ClearRegionRects(NonClientRegionKind.Passthrough);
        }
    }
}

📊 Benefits

Benefit Impact
Performance Avoids expensive transform calculations when title bar is hidden
Clarity Single cached visibility variable makes logic obvious
Correctness Same behavior, just more efficient
Maintainability Easier to understand the visibility gating logic

🤖 Model Agreement (4/4 Consensus)

All models (Claude Sonnet, Claude Opus, Gemini, GPT-5.2 Codex) identified these exact same issues and suggested identical fixes.


Verdict: Current implementation is correct and solves the bug, but the suggested refactor improves performance and clarity without changing behavior.

Cache visibility check to avoid duplicate property access and gate the
expensive TransformToVisual loop behind visibility check to avoid
unnecessary calculations when title bar is hidden.

Based on unanimous feedback from 4 AI models (Claude Sonnet, Claude Opus,
Gemini, GPT-5.2 Codex) during code review.
@PureWeen
Copy link
Member

/azp run

@PureWeen
Copy link
Member

@devanathan-vaithiyanathan let me know if my last commit is alright and you agree with the changes

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@devanathan-vaithiyanathan
Copy link
Contributor Author

let me know if my last commit is alright and you agree with the changes

Yes @PureWeen , changes are fine

@PureWeen PureWeen changed the base branch from main to inflight/current January 27, 2026 20:11
@PureWeen PureWeen merged commit 74da379 into dotnet:inflight/current Jan 27, 2026
152 of 166 checks passed
PureWeen added a commit that referenced this pull request Jan 27, 2026
…nresponsive (#33256)

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Issue Details
On Windows, when TitleBar.IsVisible is set to false, the system caption
buttons (minimize, maximize, close) become unresponsive after resizing
the window.

### Description of Change

<!-- Enter description of the fix in this section -->
Updated WindowRootView.UpdateTitleBarContentSize() to apply passthrough
regions only when the TitleBar is visible and to clear them when it is
hidden, preventing stale regions from blocking caption button
interactions.

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #33171 

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

**Tested the behavior in the following platforms.**
- [ ] Android
- [x] Windows
- [ ] iOS
- [ ] Mac

| Before  | After  |
|---------|--------|
| **Windows**<br> <video
src="https://github.com/user-attachments/assets/6b30d580-ea49-4b5d-9e4c-f6db75897d5d"
width="600" height="300"> | **Windows**<br> <video
src="https://github.com/user-attachments/assets/52f04718-3f2e-4d5e-985b-72efac175af7"
width="600" height="300"> |

---------

Co-authored-by: Shane Neuville <shane94@hotmail.com>
PureWeen added a commit that referenced this pull request Jan 29, 2026
…nresponsive (#33256)

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Issue Details
On Windows, when TitleBar.IsVisible is set to false, the system caption
buttons (minimize, maximize, close) become unresponsive after resizing
the window.

### Description of Change

<!-- Enter description of the fix in this section -->
Updated WindowRootView.UpdateTitleBarContentSize() to apply passthrough
regions only when the TitleBar is visible and to clear them when it is
hidden, preventing stale regions from blocking caption button
interactions.

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #33171 

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

**Tested the behavior in the following platforms.**
- [ ] Android
- [x] Windows
- [ ] iOS
- [ ] Mac

| Before  | After  |
|---------|--------|
| **Windows**<br> <video
src="https://github.com/user-attachments/assets/6b30d580-ea49-4b5d-9e4c-f6db75897d5d"
width="600" height="300"> | **Windows**<br> <video
src="https://github.com/user-attachments/assets/52f04718-3f2e-4d5e-985b-72efac175af7"
width="600" height="300"> |

---------

Co-authored-by: Shane Neuville <shane94@hotmail.com>
PureWeen added a commit that referenced this pull request Feb 2, 2026
…nresponsive (#33256)

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Issue Details
On Windows, when TitleBar.IsVisible is set to false, the system caption
buttons (minimize, maximize, close) become unresponsive after resizing
the window.

### Description of Change

<!-- Enter description of the fix in this section -->
Updated WindowRootView.UpdateTitleBarContentSize() to apply passthrough
regions only when the TitleBar is visible and to clear them when it is
hidden, preventing stale regions from blocking caption button
interactions.

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #33171 

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

**Tested the behavior in the following platforms.**
- [ ] Android
- [x] Windows
- [ ] iOS
- [ ] Mac

| Before  | After  |
|---------|--------|
| **Windows**<br> <video
src="https://github.com/user-attachments/assets/6b30d580-ea49-4b5d-9e4c-f6db75897d5d"
width="600" height="300"> | **Windows**<br> <video
src="https://github.com/user-attachments/assets/52f04718-3f2e-4d5e-985b-72efac175af7"
width="600" height="300"> |

---------

Co-authored-by: Shane Neuville <shane94@hotmail.com>
github-actions bot pushed a commit that referenced this pull request Feb 4, 2026
…nresponsive (#33256)

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Issue Details
On Windows, when TitleBar.IsVisible is set to false, the system caption
buttons (minimize, maximize, close) become unresponsive after resizing
the window.

### Description of Change

<!-- Enter description of the fix in this section -->
Updated WindowRootView.UpdateTitleBarContentSize() to apply passthrough
regions only when the TitleBar is visible and to clear them when it is
hidden, preventing stale regions from blocking caption button
interactions.

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #33171 

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

**Tested the behavior in the following platforms.**
- [ ] Android
- [x] Windows
- [ ] iOS
- [ ] Mac

| Before  | After  |
|---------|--------|
| **Windows**<br> <video
src="https://github.com/user-attachments/assets/6b30d580-ea49-4b5d-9e4c-f6db75897d5d"
width="600" height="300"> | **Windows**<br> <video
src="https://github.com/user-attachments/assets/52f04718-3f2e-4d5e-985b-72efac175af7"
width="600" height="300"> |

---------

Co-authored-by: Shane Neuville <shane94@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-controls-titlebar community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When TitleBar.IsVisible = false the caption buttons become unresponsive on Windows

6 participants