Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove the close button in WinUI 3?

How can I remove the close button in WinUI 3?

Screenshot of WinUI 3 App

1

like image 791
hardlycom.m Avatar asked Oct 29 '25 19:10

hardlycom.m


1 Answers

In my limited experience with WinUI 3, I cannot only remove the close button, however, it is possible to hide the whole title bar area.

MainWindow.xaml.cs

using Microsoft.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Windowing;

namespace WinUI3
{
    public sealed partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.InitializeComponent();

            GetAppWindowAndPresenter();
            _apw.IsShownInSwitchers = false;
            _presenter.SetBorderAndTitleBar(false, false);
        }

        private void myButton_Click(object sender, RoutedEventArgs e)
        {
            myButton.Content = "Clicked";
            this.Close();
        }

        public void GetAppWindowAndPresenter()
        {
            var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
            WindowId myWndId = Win32Interop.GetWindowIdFromWindow(hWnd);
            _apw = AppWindow.GetFromWindowId(myWndId);
            _presenter = _apw.Presenter as OverlappedPresenter;
        }
        private AppWindow _apw;
        private OverlappedPresenter _presenter;
    }
}

This piece of code will create a window without title bar (minimize button, maximize button and close button).

like image 181
georgel2020 Avatar answered Nov 01 '25 08:11

georgel2020