简体   繁体   English

如何为Windows 8.1应用程序设置最小高度?

[英]How to set minimum height for a Windows 8.1 app?

For Windows 10 UWP apps we have ApplicationView.SetPreferredMinSize() and 500 x 500 limitation for maximum minimum window size. 对于Windows 10 UWP应用程序,我们具有ApplicationView.SetPreferredMinSize()500 x 500的限制(最大最小窗口大小)。 But what about Windows 8.1 apps - is there any similar API to set the minimum width and height of the app window? 但是Windows 8.1应用程序呢-是否有任何类似的API来设置应用程序窗口的最小宽度和高度?

It seems like the default minimum height of the blank Windows 8.1 app is noticeably larger then height of the blank Windows 10 UWP app and I can't find where it may be set or changed. 似乎空白Windows 8.1应用程序的默认最小高度明显大于空白Windows 10 UWP应用程序的高度,我找不到在哪里设置或更改它。

I was wondered is it possible to change this min height and width for them now. 我想知道现在是否可以更改此最小高度和宽度。

Yeah, we can use reflection to call ApplicationView.SetPreferredMinSize method at Runtime within Windows 8.1 app to achieve what you want. 是的,我们可以在Windows 8.1应用程序的运行时中使用反射来调用ApplicationView.SetPreferredMinSize方法以实现所需的功能。 Following is a simple sample: 以下是一个简单的示例:

var appView = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView();
var setPreferredMinSizeMethod = appView.GetType().GetRuntimeMethod("SetPreferredMinSize", new Type[] { typeof(Size) });

if (setPreferredMinSizeMethod != null)
{
    setPreferredMinSizeMethod.Invoke(appView, new object[] { new Size(300, 300) });
}

After using this approach, you can change the minimum height and width of your app: 使用此方法后,您可以更改应用程序的最小高度和宽度: 在此处输入图片说明

But please note that on Windows 10, Windows 8.1 app's ApplicaitonView is mainly controlled by system. 但请注意,在Windows 10上,Windows 8.1应用程序的ApplicaitonView主要由系统控制。 If not necessary, please do not use reflection to do this. 如有必要,请不要使用反射来执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM