The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
How do I set the default window size of Universal Windows apps on the desktop? RRS feed

  • Question

  • I am aware that Universal Windows apps on Windows 10 are meant to be resized and adapt to different devices and so on but on the desktop in particular, how do I set the app I'm working on to open at a defined window size the first time the user launches it? Of course, after the user has resized the window around, my originally defined window size won't be enforced anymore and it will then use the one defined by the user. I'm really just looking to set the "first launch" size. How do I do this?
    Friday, August 28, 2015 4:43 PM

Answers

  • Hi!

    You can try this snippet, which shows you how to set a preferred launch window size and how to set a min size.

    public MainPage()
    {
        this.InitializeComponent();
    
        ApplicationView.PreferredLaunchViewSize = new Size(480, 800);
        ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
    
        // if you want not to have any window smaller than this size...
        ApplicationView.GetForCurrentView().SetPreferredMinSize(new Size(480, 800));
    }

    For a detailed discussion: http://stackoverflow.com/questions/31885979/windows-10-uwp-app-setting-window-size-on-desktop


    Friday, August 28, 2015 5:21 PM
  • var currentHeight = Window.Current.Bounds.Height;
    var currentWidth  = Window.Current.Bounds.Width;
    To store the size (to load it at each new launch) from ApplicationData.Current.LocalSettings using the SizeChanged event handler, for further info on how to handle it visit: https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn297195.aspx (a definitive read!)

    If your goal is to launch only once at a PreferredLaunchViewSize, you can use this rude solution (up to you for a better implementation with your coding style! :P)

    public MainPage()
            {
                this.InitializeComponent();
    
                var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
                if (localSettings.Values["launchedWithPrefSize"] == null)
                {
                    // first app launch only!!
                    ApplicationView.PreferredLaunchViewSize = new Size(100, 100);
                    ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
                    localSettings.Values["launchedWithPrefSize"] = true;
                }
                // resetting the auto-resizing -> next launch the system will control the PreferredLaunchViewSize
                ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.Auto;
                        
            }


    Sunday, August 30, 2015 7:05 AM

All replies

  • Hi!

    You can try this snippet, which shows you how to set a preferred launch window size and how to set a min size.

    public MainPage()
    {
        this.InitializeComponent();
    
        ApplicationView.PreferredLaunchViewSize = new Size(480, 800);
        ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
    
        // if you want not to have any window smaller than this size...
        ApplicationView.GetForCurrentView().SetPreferredMinSize(new Size(480, 800));
    }

    For a detailed discussion: http://stackoverflow.com/questions/31885979/windows-10-uwp-app-setting-window-size-on-desktop


    Friday, August 28, 2015 5:21 PM
  • Hi!

    You can try this snippet, which shows you how to set a preferred launch window size and how to set a min size.

    public MainPage()
    {
        this.InitializeComponent();
    
        ApplicationView.PreferredLaunchViewSize = new Size(480, 800);
        ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
    
        // if you want not to have any window smaller than this size...
        ApplicationView.GetForCurrentView().SetPreferredMinSize(new Size(480, 800));
    }
    

    For a detailed discussion: http://stackoverflow.com/questions/31885979/windows-10-uwp-app-setting-window-size-on-desktop


    Hi, thanks for the response! I tried that out but it's throwing error at me:

    Error CS0103 The name 'ApplicationView' does not exist in the current context HelloWorld

    EDIT:
    I searched around and figured I wasn't using the Windows.UI.ViewManagement. Once I included that, the code worked. However, how do I preserve the window size that the user has set afterwards? As of right now, it exclusively launches using my defined size.

    Friday, August 28, 2015 6:46 PM
  • It should be remembered by Windows if the user changes during the app execution, isn't it? (I'm sorry I have not the PC with me!) 

    Let me know!

    Saturday, August 29, 2015 2:35 PM
  • go to add reference -> extensions -> add the windows desktop extension sdk to your project

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Saturday, August 29, 2015 3:35 PM
  • It should be remembered by Windows if the user changes during the app execution, isn't it? (I'm sorry I have not the PC with me!) 

    Let me know!


    I thought that was the case too but it honors the PreferredLaunchViewSize even after I've resized the window and closed the application.
    Saturday, August 29, 2015 6:28 PM
  • var currentHeight = Window.Current.Bounds.Height;
    var currentWidth  = Window.Current.Bounds.Width;
    To store the size (to load it at each new launch) from ApplicationData.Current.LocalSettings using the SizeChanged event handler, for further info on how to handle it visit: https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn297195.aspx (a definitive read!)

    If your goal is to launch only once at a PreferredLaunchViewSize, you can use this rude solution (up to you for a better implementation with your coding style! :P)

    public MainPage()
            {
                this.InitializeComponent();
    
                var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
                if (localSettings.Values["launchedWithPrefSize"] == null)
                {
                    // first app launch only!!
                    ApplicationView.PreferredLaunchViewSize = new Size(100, 100);
                    ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
                    localSettings.Values["launchedWithPrefSize"] = true;
                }
                // resetting the auto-resizing -> next launch the system will control the PreferredLaunchViewSize
                ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.Auto;
                        
            }


    Sunday, August 30, 2015 7:05 AM