[英]How to limit window resize for UWP App
I want to limit my App window Width to 800 px, is there any way to do so? 我想将我的应用程序窗口宽度限制为800像素,有什么办法吗? I tried SizeChanged event by doing some logic hack but actually it's executing after the Size is changed.
我通过做一些逻辑修改来尝试了SizeChanged事件,但实际上它是在更改大小后执行的。 So there's little bit of UI throttling.
因此,UI的限制很少。
As far as I know, there is no way how to limit window size since your app could run in fullscreen mode when in table mode. 据我所知,没有办法限制窗口大小,因为您的应用程序可以在表格模式下以全屏模式运行。
However, you can set MaxWidth
and/or MaxHeight
properties on any FrameworkElement
, for example on a page. 但是,您可以在任何
FrameworkElement
(例如在页面上)设置MaxWidth
和/或MaxHeight
属性。
I've set both the properties to 500
on the red page and you can see the result here: 我在红页上都将这两个属性都设置为
500
,您可以在这里看到结果:
There is built-in support only for the minimum window size limit. 内置支持仅对最小窗口大小限制。 For this use the
ApplicationView.SetPreferredMinSize
method, where you can set the preferred minimum height and width size of you window. 为此,请使用
ApplicationView.SetPreferredMinSize
方法,您可以在其中设置窗口的首选最小高度和宽度大小。
ApplicationView.GetForCurrentView().SetPreferredMinSize(new Size(800, 800));
You need to call it in App.xaml.cs before Window.Current.Activate();
您需要在
Window.Current.Activate();
之前的App.xaml.cs中调用它Window.Current.Activate();
For the maximum there is no good way. 对于最大程度,没有什么好办法。 I don't know better solution than call
ApplicationView.TryResizeView
method in the SizeChanged
event. 我不知道比在
SizeChanged
事件中调用ApplicationView.TryResizeView
方法更好的解决方案。
在该源是示例如何调整图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.