Search code examples
uwpresizevisual-studio-2019fullscreen

How can I prevent my UWP app from being displayed fullscreen?


In connection with my issue here, and in an effort to maximize my app's form/page, I used the code recommended here:

public App()
{
    this.InitializeComponent();
    this.Suspending += OnSuspending;
    ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;
}

(the third/final line is what I added).

This worked - the app went full-screen:

enter image description here

...but then I could only get it out of the way (access any other app) by selecting "Hot Reload" and then in Visual Studio "Stop Debugging."

So I commented out that line, yet the app still displays fullscreen.

I don't really want fullScreen; I want Maximized. So I uncommented that line of code, and changed the last part of it so that it is now this:

ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.Maximized;

But it still displays fullscreen, rather than maximized.

How can I get it to stop displaying fullscreen?


Solution

  • Please try to use the following code on the main page of your app to make your screen maximized:

            var DisplayView = DisplayInformation.GetForCurrentView();
    
            var resolution = new Size(DisplayView.ScreenWidthInRawPixels, DisplayView.ScreenHeightInRawPixels);
    
            // Calculate the screen size in effective pixels. 
            var scale = DisplayView.ResolutionScale == ResolutionScale.Invalid ? 1 : DisplayView.RawPixelsPerViewPixel;
            var ViewBounds = new Size(resolution.Width / scale, resolution.Height / scale);
    
            ApplicationView.PreferredLaunchViewSize = new Size(ViewBounds.Width, ViewBounds.Height);
            ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
    

    Please note that the Maximized window will work when you launch the app for the seconde time. This is mentioned here: ApplicationView.PreferredLaunchWindowingMode Property