microsoft-ui-xaml icon indicating copy to clipboard operation
microsoft-ui-xaml copied to clipboard

Is there a way to open the app in full screen without a taskbar with WinUI 3

Open raushanalert opened this issue 3 years ago • 11 comments
trafficstars

Describe the bug

any solution to open the app in full screen without a taskbar. (for now we are setting taskbar settings manually (hide))disable / hide window buttons ( minimize , maximize , close buttons). I have tried to open the app in fullscreen by ApplicationViewWindowingMode.FullScreen but this code is not supported by the application. App FullScreen Issue

Steps to reproduce the bug

Just Run App default screen showing

Expected behavior

open the app in fullscreen without a taskbar

Screenshots

defaultscreen

NuGet package version

WinUI 3 - Windows App SDK 1.0 (If you're seeing your issue in older previews of WinUI 3, please try this release)

Windows app type

  • [X] UWP
  • [ ] Win32

Device form factor

Desktop

Windows version

May 2021 Update (19043)

Additional context

No response

raushanalert avatar Jan 13 '22 12:01 raushanalert

@codendone @marb2000 @MikeHillberg any of you know the correct way to do this in Winui3?

StephenLPeters avatar Mar 02 '22 18:03 StephenLPeters

With the release of MAUI and now Visual Studio 17.3.0 I still see this behaviour. Is there any update on why this doesn't work or if there is a correct way to approach this with WinUI3?

FrogsLegs avatar Aug 15 '22 13:08 FrogsLegs

You can set FullScreen with AppWindow.SetPresenter and Microsoft.UI.Windowing.AppWindowPresenterKind.FullScreen

castorix avatar Aug 15 '22 14:08 castorix

You can set FullScreen with AppWindow.SetPresenter and Microsoft.UI.Windowing.AppWindowPresenterKind.FullScreen

Thanks, that does almost work! ....

    `var currentWindow = Application.Windows[0].Handler.PlatformView;
    IntPtr _windowHandle = WindowNative.GetWindowHandle(currentWindow);
    var windowId = Win32Interop.GetWindowIdFromWindow(_windowHandle);

    AppWindow appWindow = AppWindow.GetFromWindowId(windowId);
    appWindow.SetPresenter(AppWindowPresenterKind.FullScreen);`

The Window bar is weirdly half cut off though:

image

FrogsLegs avatar Aug 15 '22 15:08 FrogsLegs

The Window bar is weirdly half cut off though:

I cannot reproduce this on my configuration (Windows App SDK 1.1.0, Windows 10 21H1) (I can only get this small caption with SetBorderAndTitleBar and not FullScreen)

castorix avatar Aug 15 '22 16:08 castorix

The Window bar is weirdly half cut off though:

Had the same issue, but the following solution works for me:

            var mauiWindow = handler.VirtualView;
            var nativeWindow = handler.PlatformView;
            nativeWindow.Activate();
            IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(nativeWindow);
            WindowId windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(windowHandle);
            AppWindow appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId);
            
            if(appWindow.Presenter is OverlappedPresenter p)
            {
                p.Maximize();
            }

wulf11 avatar Aug 19 '22 07:08 wulf11

The Window bar is weirdly half cut off though:

I cannot reproduce this on my configuration (Windows App SDK 1.1.0, Windows 10 21H1) (I can only get this small caption with SetBorderAndTitleBar and not FullScreen)

I've created a sample repo here. Can you please test this on your machine and compare the results. I'm running Win 11 21H2.

FrogsLegs avatar Aug 22 '22 10:08 FrogsLegs

您可以使用AppWindow.SetPresenter_和_Microsoft.UI.Windowing.AppWindowPresenterKind.FullScreen_设置 FullScreen_

谢谢,这几乎可以工作!……

    `var currentWindow = Application.Windows[0].Handler.PlatformView;
    IntPtr _windowHandle = WindowNative.GetWindowHandle(currentWindow);
    var windowId = Win32Interop.GetWindowIdFromWindow(_windowHandle);

    AppWindow appWindow = AppWindow.GetFromWindowId(windowId);
    appWindow.SetPresenter(AppWindowPresenterKind.FullScreen);`

窗口栏奇怪地被截断了一半:

图片

you need to hide the titlebar var nativeWindow = handler.PlatformView; var winuiWindow = nativeWindow as Microsoft.UI.Xaml.Window; winuiWindow.ExtendsContentIntoTitleBar = false;

ligf avatar Aug 23 '22 02:08 ligf

you need to hide the titlebar var nativeWindow = handler.PlatformView; var winuiWindow = nativeWindow as Microsoft.UI.Xaml.Window; winuiWindow.ExtendsContentIntoTitleBar = false;

Yes I have done that in the sample here. Still the TitleBar is half visible on Win 11 21H2. Can you see different behaviour when running the sample?

FrogsLegs avatar Aug 23 '22 08:08 FrogsLegs

Does anyone have a working sample on Win 11 21H2 that runs TopMost full screen?

FrogsLegs avatar Aug 26 '22 08:08 FrogsLegs

@FrogsLegs Taking the code from WindowingInterop.cs class in WindowsAppSDK Samples repo let my app works in fullscreen mode (directly at startup, no button to enter/exit fullsreen mode).

OculiViridi avatar Sep 16 '22 09:09 OculiViridi

net7.0rc-1 (Only tested with MAUI)

Windows

MauiProgram.cs
#if WINDOWS
            // using Microsoft.Maui.LifecycleEvents;
            // #if WINDOWS
            //            using Microsoft.UI;
            //            using Microsoft.UI.Windowing;
            //            using Windows.Graphics;
            // #endif

            builder.ConfigureLifecycleEvents(events =>
                {
                    events.AddWindows(windowsLifecycleBuilder =>
                        {
                            windowsLifecycleBuilder.OnWindowCreated(window =>
                                {
                                    window.ExtendsContentIntoTitleBar = false;
                                    var handle = WinRT.Interop.WindowNative.GetWindowHandle(window);
                                    var id = Win32Interop.GetWindowIdFromWindow(handle);
                                    var appWindow = AppWindow.GetFromWindowId(id);
                                    switch (appWindow.Presenter)
                                    {
                                        case OverlappedPresenter overlappedPresenter:
                                            overlappedPresenter.SetBorderAndTitleBar(false, false);
                                            overlappedPresenter.Maximize();
                                            break;
                                    }
                                });
                        });
                });
#endif

Android

Platforms/Android/MainActivity.cs
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)]
public class MainActivity : MauiAppCompatActivity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        Platform.Init(this, savedInstanceState);

        this.Window?.AddFlags(WindowManagerFlags.Fullscreen);
    }
}

(Edit MainPage.xml if you are still not full screen in windows)

<?xml version="1.0" encoding="UTF-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:YourApp"
             x:Class="YourApp.MainPage"
             Title=""
             NavigationPage.HasNavigationBar="False">

    <BlazorWebView HostPage="wwwroot/index.html">
        <BlazorWebView.RootComponents>
            <RootComponent Selector="#app" ComponentType="{x:Type local:Main}" />
        </BlazorWebView.RootComponents>
    </BlazorWebView>

</ContentPage>

image

LahkLeKey avatar Oct 10 '22 01:10 LahkLeKey

For WinUI 3 App you can use this code

App.MainWindow.ExtendsContentIntoTitleBar = true; Microsoft.UI.Windowing.AppWindow _appWindow; _appWindow = GetAppWindowForCurrentWindow(); _appWindow.SetPresenter(AppWindowPresenterKind.FullScreen);

private Microsoft.UI.Windowing.AppWindow GetAppWindowForCurrentWindow() { IntPtr hWnd = WindowNative.GetWindowHandle(App.MainWindow); WindowId myWndId = Win32Interop.GetWindowIdFromWindow(hWnd); return Microsoft.UI.Windowing.AppWindow.GetFromWindowId(myWndId); }

This will help you

isourabhsingh avatar Feb 03 '23 07:02 isourabhsingh

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Aug 03 '23 22:08 github-actions[bot]

Closing this issue as it appears to have had multiple solutions presented and has had no activity in 10 months.

duncanmacmichael avatar Dec 09 '23 01:12 duncanmacmichael

This issue somehow gets a new way to solve in #9674 😄

HO-COOH avatar May 25 '24 17:05 HO-COOH