Search code examples
c#winui-3winuiwindows-app-sdk

Create topmost fullscreen window without titlebar, but desktop's taskbar must be visible


I'm using WinUI3, and I need to create topmost fullscreen borderless window without titlebar, but taskbar must be visible. My window must be always on top, it should not hide when I press Win+D I tried to set AppWindow's Presenter to CompactOverlay and set size manually, but titlebar is visible. I tried to set AppWindow's Presenter to Fullscreen, but it hides taskbar, if i set size, window can be hidden. Example of window, which i need(My window is all gray area)


Solution

  • This should work:

    public sealed partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.InitializeComponent();
    
            _presenter = this.AppWindow.Presenter as OverlappedPresenter;
            this.Activated += MainWindow_Activated;
        }
    
        private OverlappedPresenter? _presenter;
    
        private void MainWindow_Activated(object sender, WindowActivatedEventArgs args)
        {
            if (_presenter is null)
            {
                return;
            }
    
            _presenter.Maximize();
            _presenter.SetBorderAndTitleBar(hasBorder: false, hasTitleBar: false);
            _presenter.IsAlwaysOnTop = true;
        }
    }