简体   繁体   中英

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? I tried SizeChanged event by doing some logic hack but actually it's executing after the Size is changed. So there's little bit of UI throttling.

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.

I've set both the properties to 500 on the red page and you can see the result here:

例

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.GetForCurrentView().SetPreferredMinSize(new Size(800, 800));

You need to call it in App.xaml.cs before 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.

在该是示例如何调整图。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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