How to ensure UWP app is always full screen on launch?

Viewed 8257

Is there a way (either C# or XAML) I can maximize a UWP app window even after I resized and closed it previously on desktop?

I have tried with ApplicationViewWindowingMode.FullScreen but this makes the app go entire full screen and covers the Windows Taskbar too.

5 Answers

If you want to MAXIMISE your app on launch you can use the following:

ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.Maximized;

But be sure to put it into the Loaded Event for your Page or it will not work!

I've too few points to comment directly. None of the above resized to a maximized view for me (or the below single-line ApplicationViewWindowingMode.Maximized method), but I have used some of the answers to come up with something that worked for me. It is still very clunky however. The screen size given in 'DisplayInformation' is too big to allow the page to be resized directly to it. Trying to do it didn't work and I had to take 60 off height and width to get it to return 'true', therefore I have the following bit of nonsense which worked, maybe it will help someone else find a better answer. It goes in the page/window loaded event. Nothing else needs to be added elsewhere.

        private void Page_Loaded(object sender, RoutedEventArgs e)
    {
        var view = ApplicationView.GetForCurrentView();
        var displayInfo = DisplayInformation.GetForCurrentView();
        double x = ActualWidth;
        double y = ActualHeight;
        bool answer = true;

        // Get the screen resolution (APIs available from 14393 onward).
        var resolution = new Size(displayInfo.ScreenWidthInRawPixels-60, displayInfo.ScreenHeightInRawPixels-60);

        answer = view.TryResizeView(resolution); //This should return true if the resize is successful
        if (answer)
        {
            x = displayInfo.ScreenWidthInRawPixels - 60;
            y = displayInfo.ScreenHeightInRawPixels - 60;
        }
        answer = true;
        while (answer == true)
        {
            x++;
            answer = view.TryResizeView(new Size { Width = x, Height = y });
        }
        x = x - 1;
        answer = true;
        while (answer == true)
        {
            y++;
            answer = view.TryResizeView(new Size { Width = x, Height = y });
        }

Adding the following line to the OnLaunched event under App.xaml.cs did it for me.

ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;

NOTE: Make sure to add it before the following line

 Window.Current.Activate();

If you like to go fullscreen at the runtime use the following line.

ApplicationView.GetForCurrentView().TryEnterFullScreenMode();

I have this one liner that works as I expected Justins code to, but for some reason, when using Justins answer, my window would not be maximized... But then I changed something that did make it maximized but I lost all my fluent design such as Acrylic and RevealHighlite...

So I came up with this one liner which keeps all of my fluent design principles happy:

ApplicationView.GetForCurrentView().TryEnterFullScreenMode();

Something to note:

I did try Justins answer, and I am using his method of MaximizeWindowOnLoad() which I have called straight after the initializeComponent();

Full overview:

public class()
        {     
            this.InitializeComponent();
            MaximizeWindowOnLoad();   
        }

private static void MaximizeWindowOnLoad()
        { 
           ApplicationView.GetForCurrentView().TryEnterFullScreenMode();
        }
Related