1

I would like to set min size like 800x600 for my windows universal app which on desktop.

I found a method

ApplicationView.GetForCurrentView().SetPreferredMinSize(new Size(800, 600));

but it doesn't work, I still can drag the window to 500x300.

What I miss ?

PatrickSCLin
  • 1,419
  • 3
  • 17
  • 45

3 Answers3

2

I found a solution https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.viewmanagement.applicationview.tryresizeview

for desktop, I can set a min size which is bigger than 500x500 as below code.

private void Page_SizeChanged(object sender, SizeChangedEventArgs e)
{
    if (e.NewSize.Width < 800 || e.NewSize.Height < 600)
    {
        ApplicationView.GetForCurrentView().TryResizeView(new Size(800, 600));
    }
}
PatrickSCLin
  • 1,419
  • 3
  • 17
  • 45
  • 1
    Thanks Patrick. A small improvement is here: ApplicationView.GetForCurrentView().TryResizeView(new Size(Math.Max(800, e.NewSize.Width), Math.Max(600, e.NewSize.Height))); – Art Dumas Apr 24 '17 at 13:17
  • 1
    This works, but it look very bad. As user is dragging, the window actually gets smaller than specified and there's flickering as the code "fights" the user. There must be a better way. It's so bizarre that MS would hard code this to 500x500 and not let the developer change it. – under May 30 '17 at 08:48
1

From MSDN:

The largest allowed minimum size is 500 x 500 effective pixels. If you set a value outside of these bounds, it is coerced to be within the allowed bounds.

Maybe this is the reason

MSDN Page

Mirko Bellabarba
  • 562
  • 2
  • 13
0

For my app I am setting it to run on the Desktop at a startup height of 480 and a width of 320.

On my Mainpage's code behind file I call the following method:

    public MainPage()
    {
      GetDeviceFormFactorType();
    }


       public static DeviceFormFactorType GetDeviceFormFactorType()
    {
        switch (AnalyticsInfo.VersionInfo.DeviceFamily)
        {
            case "Windows.Mobile":
                return DeviceFormFactorType.Phone;
            case "Windows.Desktop":
                ApplicationView.GetForCurrentView().SetPreferredMinSize(new Size { Width = 320, Height = 480 });
                ApplicationView.PreferredLaunchViewSize = new Size { Height = 480, Width = 320 };
                ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
                return DeviceFormFactorType.Desktop;
            case "Windows.Tablet":
                return DeviceFormFactorType.Tablet;
            case "Windows.Universal":
                return DeviceFormFactorType.Iot;
            case "Windows.Team":
                return DeviceFormFactorType.SurfaceHub;
            default:
                return DeviceFormFactorType.other;
        }
    }


        public enum DeviceFormFactorType
    {
        Phone,
        Desktop,
        Tablet,
        Iot,
        SurfaceHub,
        other
    }
Mark Garcia
  • 221
  • 1
  • 2
  • 15