2

I'm trying to create a new window in my Windows 10 application but I want to be able to specify the initial size for the created window.

So far I'm trying as so, with no luck -

            var currentAppView = ApplicationView.GetForCurrentView();

            var newCoreAppView = CoreApplication.CreateNewView();
            await newCoreAppView.Dispatcher.RunAsync(
                          CoreDispatcherPriority.Normal,
                          async () =>
                          {
                              var newWindow = Window.Current;
                              var newAppView = ApplicationView.GetForCurrentView();
                              newAppView.SetPreferredMinSize(new Size(1, 1));
                              newAppView.TryResizeView(new Size(300, 300));
                              newAppView.Title = "New small window";

                              var frame = new Frame();
                              frame.Navigate(typeof(NewPage), null);
                              newWindow.Content = frame;
                              newWindow.Activate();

                              await ApplicationViewSwitcher.TryShowAsStandaloneAsync(
                                    newAppView.Id,
                                    ViewSizePreference.UseMinimum,
                                    currentAppView.Id,
                                    ViewSizePreference.UseMinimum);
                          });
BradStevenson
  • 1,974
  • 7
  • 26
  • 40

1 Answers1

1

Resize the window after it's shown.

await ApplicationViewSwitcher.TryShowAsStandaloneAsync(
    newAppView.Id,
    ViewSizePreference.UseMinimum,
    currentAppView.Id,
    ViewSizePreference.UseMinimum);

newAppView.TryResizeView(new Size(300, 300));
Igor Ralic
  • 14,975
  • 4
  • 43
  • 51
  • Whilst this does work, occasionally it shows the splash screen at the same size before resizing which can be jarring. Also this can cause the app to reopen from scratch at the smaller size unfortunately – BradStevenson Jul 21 '15 at 20:04