Skip to content

CenterContent in TitleBar control does not stretch properly #10421

@Zakariathr22

Description

@Zakariathr22

Description:

The CenterContent inside the TitleBar does not stretch properly due to the ContentPresenter being constrained by HorizontalAlignment="Center". This causes issues when adding controls like AutoSuggestBox, which remain centered instead of filling the available space.

Steps to Reproduce:

  1. Add a control (e.g., AutoSuggestBox) to the CenterContent of the TitleBar.
  2. Observe that the control remains centered and does not stretch, even if HorizontalAlignment="Stretch" is set on the child element.
  3. Resizing the window may result in unintended cropping if explicit widths are set.

Actual Behavior:

  • Controls take up the full height of the title bar, which is inconsistent with the rest of the title bar layout.
  • Controls remain centered and do not stretch.
    image
  • Manually setting widths leads to cropping issues on window resize.
    GIF
<TitleBar.CenterContent>
    <AutoSuggestBox x:Name="SearchBox" Width="480" PlaceholderText="Search..." QueryIcon="Find"/>
</TitleBar.CenterContent>

Expected Behavior:

  • Controls inside the CenterContent should stretch properly to fit the available space while maintaining correct alignment with other title bar elements.
  • Controls inside the center content area must follow the TitleBar specs correctly (The follwing design from titleBar-dev-spec)
    image

Attempted Solution:

I removed HorizontalAlignment="Center" from the ContentPresenter to allow child elements to stretch properly and set VerticalAlignment="Center" to keep alignment consistent with other title bar elements.

<Grid
    x:Name="PART_CenterContentPresenterGrid"
    x:DeferLoadStrategy="Lazy"
    Visibility="Collapsed"
    Grid.Column="8">
    <ContentPresenter
        x:Name="PART_CenterContentPresenter"
        Content="{TemplateBinding CenterContent}"
        VerticalAlignment="Center"/>
</Grid>

Result of Attempted Fix:

  • ✅ The CenterContent stretched correctly, and child elements like AutoSuggestBox behaved as expected.
  • ❌ However, clicking on the center area of the title bar no longer allowed dragging the window.
Recording.2025-03-12.125951.mp4
<TitleBar.CenterContent>
    <AutoSuggestBox x:Name="SearchBox" MaxWidth="480" PlaceholderText="Search..." QueryIcon="Find"/>
</TitleBar.CenterContent>

NuGet package version

WinUI 3 - Windows App SDK 1.7 Preview 1: 1.7.250208002-preview1

Windows version

Windows 11 (24H2): Build 26100

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-TitleBarIssues related to custom window title bars.bugSomething isn't workingclosed-DuplicateDescribed behavior is already captured by another issue.needs-triageIssue needs to be triaged by the area ownersteam-ControlsIssue for the Controls team

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions