none
[UWP]How to set Maximize or Resize second window(view) on Multiple View of UWP? RRS feed

  • Question

  • Hello,

    I like to open new Window on the next screen with 'Maximized' Screen from Main page.
    - detail: user clicks a button -> system opens new window on the different monitor maximized.

    **Limitation: I cannot use 'AppWindow' since it does not support Multimedia Full screen.

    I used Multiple View sample and implemented the multiple view with no issue. But I cannot find reliable way to Size the secondary view and maximize the window. 

    ApplicationView.GetForCurrentView().SetPreferredMinSize or any methods using ApplicationView.GetForCurrentView() does not work because it resize Main window as well.

    I found many way to do this only for ONE window. But, not for Multiple windows. (Multiple View)

    Any help, please..?

    Thank you,


    MCSD .NET, SCJP, SCJWD


    Thursday, August 29, 2019 4:49 PM

Answers

  • Hi,

    After testing, I found a way that might be able to resize the second view that you created using CoreApplication.CreateNewView().

    Like this:

     private async void Button_Click(object sender, RoutedEventArgs e)
            {
                var rect = Window.Current.Bounds;
                var oldCurrentView = ApplicationView.GetForCurrentView();
                CoreApplicationView newView = CoreApplication.CreateNewView();
                ApplicationView newCurrentView = null;
                await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    Frame frame = new Frame();
                    frame.Navigate(typeof(SecondaryPage), null);
                    Window.Current.Content = frame;
                    Window.Current.Activate();
                    newCurrentView = ApplicationView.GetForCurrentView();
                });
    
                await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newCurrentView.Id, ViewSizePreference.UseHalf, oldCurrentView.Id,ViewSizePreference.UseHalf);
                newCurrentView.TryResizeView(new Size { Width = rect.Width - 300, Height = rect.Height - 200 });
            }

    So the key point it to use TryResizeView method to assign the size you want to the new View.

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, August 30, 2019 6:37 AM
    Moderator

All replies

  • Hi,

    After testing, I found a way that might be able to resize the second view that you created using CoreApplication.CreateNewView().

    Like this:

     private async void Button_Click(object sender, RoutedEventArgs e)
            {
                var rect = Window.Current.Bounds;
                var oldCurrentView = ApplicationView.GetForCurrentView();
                CoreApplicationView newView = CoreApplication.CreateNewView();
                ApplicationView newCurrentView = null;
                await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    Frame frame = new Frame();
                    frame.Navigate(typeof(SecondaryPage), null);
                    Window.Current.Content = frame;
                    Window.Current.Activate();
                    newCurrentView = ApplicationView.GetForCurrentView();
                });
    
                await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newCurrentView.Id, ViewSizePreference.UseHalf, oldCurrentView.Id,ViewSizePreference.UseHalf);
                newCurrentView.TryResizeView(new Size { Width = rect.Width - 300, Height = rect.Height - 200 });
            }

    So the key point it to use TryResizeView method to assign the size you want to the new View.

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, August 30, 2019 6:37 AM
    Moderator
  • Thank you so much!

    MCSD .NET, SCJP, SCJWD

    Thursday, September 5, 2019 8:40 PM