0

I am currently using Winui-3 and the Windows App SDK for the first time as I usually write apps in classic Win32 C++. My app has a tall title bar (48px) and I want the caption buttons to be sized appropriately. I have already tried using the method from the Microsoft docs, but that causes CS0120: AppWindowTitleBar.PreferredHeightOption = TitleBarHeightOption.Tall;

I have not found any solutions to this exact problem online. Putting it into a static method did not work. While experimenting, I've found that other customizations like AppWindowTitleBar.ForegroundColor = Colors.White; also don't work. I am confused.

EDIT: Added implementation of the title bar

public ShellPage(ShellViewModel viewModel)
    {
        ViewModel = viewModel;
        InitializeComponent();

        ViewModel.NavigationService.Frame = NavigationFrame;
        ViewModel.NavigationViewService.Initialize(NavigationViewControl);

        AppWindowTitleBar.PreferredHeightOption = TitleBarHeightOption.Tall;

        App.MainWindow.ExtendsContentIntoTitleBar = true;
        App.MainWindow.SetTitleBar(AppTitleBar);
        App.MainWindow.Activated += MainWindow_Activated;
        AppTitleBarText.Text = "AppDisplayName".GetLocalized();
    }
Davide_24
  • 67
  • 7

1 Answers1

0

The AppWindowTitleBar doesn't have PreferredHeightOption. That's why you're getting CS0120.

Try this.

public ShellPage(ShellViewModel viewModel)
{
    ViewModel = viewModel;
    InitializeComponent();

    ViewModel.NavigationService.Frame = NavigationFrame;
    ViewModel.NavigationViewService.Initialize(NavigationViewControl);

    //AppWindowTitleBar.PreferredHeightOption = TitleBarHeightOption.Tall;

    App.MainWindow.ExtendsContentIntoTitleBar = true;  // not sure if you need this line.
    this.appWindow = GetAppWindowForCurrentWindow();
    this.appWindow.TitleBar.ExtendsContentIntoTitleBar = true;
    this.appWindow.TitleBar.PreferredHeightOption = TitleBarHeightOption.Tall;
    App.MainWindow.SetTitleBar(AppTitleBar);
    App.MainWindow.Activated += MainWindow_Activated;
    AppTitleBarText.Text = "AppDisplayName".GetLocalized();
}

private AppWindow appWindow;

private AppWindow GetAppWindowForCurrentWindow()
{
    IntPtr hWnd = WindowNative.GetWindowHandle(App.MainWindow);
    WindowId wndId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hWnd);
    return AppWindow.GetFromWindowId(wndId);
}
Andrew KeepCoding
  • 7,040
  • 2
  • 14
  • 21
  • 1
    Also Give [Windowing](https://github.com/microsoft/WindowsAppSDK-Samples/blob/d8fffa2888095cd0f0218cc2b8c01fd33a433301/Samples/Windowing/cs-winui/TitleBarPage.xaml.cs#L159) a try And According to [System caption buttons](https://learn.microsoft.com/en-us/windows/apps/develop/title-bar?tabs=wasdk#system-caption-buttons), The feature is Windows 11 only. – YangXiaoPo-MSFT Aug 18 '22 at 02:20