1

I'm developing an UWP app and I would like to set a minimum window size (in desktop)

I've been looking and I do not know where this is done.

2 Answers 2

6

You can set some of 'Windows' properties in ApplicationView class. There is a method that allows to set the Minimum size of application window (desktop only) - SetPreferredMinSize. However, this accepts values only from certain range:

The smallest allowed minimum size is 192 x 48 effective pixels. 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.

To do what you want you will have to set it upon app launching:

ApplicationView.GetForCurrentView().SetPreferredMinSize(new Size(300, 300));

Note that you also can set a preferred launch size with other property:

ApplicationView.PreferredLaunchViewSize = new Size(600, 600);
Sign up to request clarification or add additional context in comments.

6 Comments

One key thing to note Is that you are providing DIPS, not PIXELS, for this API. See this code for an example of usage.
@FernandoSousa You should put this in app.xaml.cs before activating the window.
It gives an error. This is my app.xaml.cs: sealed partial class App : BootStrapper { public App() { InitializeComponent(); SplashFactory = (e) => new Views.Splash(e); } public override async Task OnStartAsync(StartKind startKind, IActivatedEventArgs args) { // TODO: add your long-running task here await NavigationService.NavigateAsync(typeof(Views.MainPage)); } }
@FernandoSousa You have provided too little code and no exception message and information. Besides, I don't see how this is connected to my answer and comments shouldn't be used to ask new questions.
This is my code, I do not know where to put this code: ApplicationView.GetForCurrentView().SetPreferredMinSize(new Size(300, 300));
|
0

As you can see here you can use minWidth and minHeight properties in the xaml.

1 Comment

This is for the page control not the window size

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.