Skip to content

Window.SetTitleBar(null) does not restore the default drag region. #10694

@nandin-borjigin

Description

@nandin-borjigin

Describe the bug

As per the documentation, calling SetTitleBar(null) should reset the drag region to default. However, it does so only if ExtendsContentIntoTitleBar is toggled after calling it.

Steps to reproduce the bug

<?xml version="1.0" encoding="utf-8" ?>
<Window
    x:Class="App1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="using:App1"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Title="App1"
    mc:Ignorable="d">

    <Window.SystemBackdrop>
        <MicaBackdrop />
    </Window.SystemBackdrop>
    <Border>
        <StackPanel
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            Orientation="Vertical">
            <TextBlock
                x:Name="Output"
                HorizontalAlignment="Center"
                Text="Default" />
            <StackPanel
                HorizontalAlignment="Center"
                Orientation="Horizontal"
                Spacing="12">
                <Button
                    x:Name="Restore"
                    Click="Restore_Click"
                    Content="Restore" />
                <Button
                    x:Name="Custom"
                    Click="Custom_Click"
                    Content="Custom" />
            </StackPanel>
        </StackPanel>
    </Border>
</Window>
using Microsoft.UI.Xaml;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace App1
{
    /// <summary>
    /// An empty window that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            ExtendsContentIntoTitleBar = true;
        }

        private void Restore_Click(object sender, RoutedEventArgs e)
        {
            Output.Text = "Default";
            SetTitleBar(null);
           
            // It wouldn't work unless the following lines are uncommented.
            // i.e., the `Content` still responds to drag after executing the above lines.
            // ExtendsContentIntoTitleBar = false;
            // ExtendsContentIntoTitleBar = true;
        }

        private void Custom_Click(object sender, RoutedEventArgs e)
        {
            Output.Text = "Custom";
            SetTitleBar(Content);
        }
    }
}

Expected behavior

SetTitleBar(null) should restore the default drag region.

Screenshots

Video.mp4

NuGet package version

WinUI 3 - Windows App SDK 1.7.3: 1.7.250606001

Windows version

Windows 11 (24H2): Build 26100

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-TitleBarIssues related to custom window title bars.bugSomething isn't working

    Type

    No type

    Projects

    Status

    Ready

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions