Zea Shah
Zea Shah

Reputation: 382

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.

Upvotes: 1

Views: 3096

Answers (3)

Влад Макух
Влад Макух

Reputation: 311

In this source is example how resize view.

Upvotes: 0

Tóth Tibor
Tóth Tibor

Reputation: 1565

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.

Upvotes: 2

Marian Dolinský
Marian Dolinský

Reputation: 3492

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:

Example

Upvotes: 2

Related Questions