问题
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 ?
回答1:
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));
}
}
回答2:
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
回答3:
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
}
来源:https://stackoverflow.com/questions/35791451/how-to-set-min-size-of-windows-universal-app-on-desktop