microsoft / microsoft-ui-xaml

WinUI: a modern UI framework with a rich set of controls and styles to build dynamic and high-performing Windows applications.
MIT License
6.38k stars 683 forks source link

TitleBar doesn't respect AppWindow.TitleBar.PreferredHeightOption #9863

Open brunosonnino opened 3 months ago

brunosonnino commented 3 months ago

Describe the bug

The TitleBar has always the Standard Height and doesn't respect the AppWindow.TitleBar.PreferredHeightOption setting

Steps to reproduce the bug

<WindowsSdkPackageVersion>10.0.19041.35-preview</WindowsSdkPackageVersion>

Add this code in MainWindow.xaml.cs

public sealed partial class MainWindow : Window
{
    public string[] TitleBarHeights = ["Standard", "Tall", "Collapsed"];
    public MainWindow()
    {
        this.InitializeComponent();
        ExtendsContentIntoTitleBar = true;
    }

    private void TitleBarHeight_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (sender is RadioButtons radioButtons)
        {
            AppWindow.TitleBar.PreferredHeightOption = radioButtons.SelectedIndex switch
            {
                1 => TitleBarHeightOption.Tall,
                2 => TitleBarHeightOption.Collapsed,
                _ => TitleBarHeightOption.Standard
            };
        }
    }
}

Add this code to MainWindow.xaml

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <TitleBar Title="Title" Subtitle="SubTitle" IsBackButtonVisible="True" IsPaneToggleButtonVisible="True">
        <TitleBar.IconSource>
            <FontIconSource Glyph="&#xe713;" />
        </TitleBar.IconSource>
    </TitleBar>
    <Grid Grid.Row="1" Background="Aqua">
        <RadioButtons ItemsSource="{x:Bind TitleBarHeights}" HorizontalAlignment="Center" VerticalAlignment="Center"
                SelectedIndex="0" SelectionChanged="TitleBarHeight_SelectionChanged" />
    </Grid>
</Grid>

Run the project. If you change the radio button, the bar stays the same, but the title bar height changes (you can check by trying the buttons and the in-app-toolbar in the app). For the Collapsed settings, the buttons disappear, and you can't move the window anymore

This project has a sample of the bug: https://github.com/brunosonnino/TitleBarBugs/tree/main/2%20-%20TitleBarHeight

Expected behavior

The TitleBar should respect the setting

Screenshots

image Standard image Tall image Collapsed

NuGet package version

WinUI 3 - Windows App SDK 1.6 Experimental 2: 1.6.240701003-experimental2

Windows version

Windows 11 (22H2): Build 22621

Additional context

No response

github-actions[bot] commented 3 months ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

ghost1372 commented 3 months ago

@brunosonnino this is working fine. It seems you forgot to apply the title bar:

public MainWindow()
{
    this.InitializeComponent();
    ExtendsContentIntoTitleBar = true;
    SetTitleBar(AppTitleBar);
}

<TitleBar Title="Hello" Subtitle="v1.2.3" x:Name="AppTitleBar"/>

All options work well xx

you can close this issue

brunosonnino commented 3 months ago

@ghost1372 The problem is not in the titlebar buttons - it's in the Titlebar itself - in your gif, you can see that the titlebar has always the same height, it doesn't change, but it should change height (or disappear when you choose collapsed). The buttons change, but the titlebar (which should change), no

ghost1372 commented 3 months ago

@brunosonnino oh i got it Adding content may solve the problem, but it adds other problems

<TitleBar.Content>
    <AutoSuggestBox Width="320"/>
</TitleBar.Content>
brunosonnino commented 3 months ago

@ghost1372 when you add the autosuggest, it goes to tall, but doesn't return to standard or hide