1

In the following code I can not tinker with the ViewSizePreference options and get the child to be smaller than the parent. I am making a popup from a page. That part works fine. However, both windows are the exact same size.

private async void Test_Click(object sender,RoutedEventArgs e){
var currentAV = ApplicationView.GetForCurrentView();
var newAV = CoreApplication.CreateNewView();
await newAV.Dispatcher.RunAsync(
                CoreDispatcherPriority.Normal,
                async () =>
                {
                    var newWindow = Window.Current;
                    var newAppView = ApplicationView.GetForCurrentView();
                    newAppView.Title = "New window";

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

                    await ApplicationViewSwitcher.TryShowAsStandaloneAsync(
                        newAppView.Id,
                        ViewSizePreference.UseMinimum,
                        currentAV.Id,
                        ViewSizePreference.UseMinimum);
                });
}
Rick
  • 106
  • 9
  • Why don't u use `` control? [Pupup class](https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.primitives.popup.aspx) – Hassaan Akbar Aug 27 '16 at 21:29
  • Hassaan: I am trying Popup now but have not yet been able to slide it around the display. This is one of my requirements. – Rick Aug 30 '16 at 14:15

1 Answers1

1

However, both windows are the exact same size.

Yes, I just found the same issue, and I've reported this issue. As soon as I get the response of this issue, I will post here.

By now, we can use a workaround to solve this problem, since your want to expand a new window with a smaller size than the main window, you can use ApplicationView.TryResizeView | tryResizeView method to set the size of new window programmatically.

For example:

private async void Test_Click(object sender, RoutedEventArgs e)
{
    var currentAV = ApplicationView.GetForCurrentView();
    //get the bounds of current window.
    var rect = Window.Current.Bounds;
    var newAV = CoreApplication.CreateNewView();
    await newAV.Dispatcher.RunAsync(
                    CoreDispatcherPriority.Normal,
                    async () =>
                    {
                        var newWindow = Window.Current;
                        var newAppView = ApplicationView.GetForCurrentView();
                        newAppView.Title = "New window";

                        var frame = new Frame();
                        //send current window's size as parameter.
                        frame.Navigate(typeof(MainPage), rect.Width.ToString() + ":" + rect.Height.ToString());
                        newWindow.Content = frame;
                        newWindow.Activate();

                        await ApplicationViewSwitcher.TryShowAsStandaloneAsync(
                            newAppView.Id,
                            ViewSizePreference.UseHalf,
                            currentAV.Id,
                            ViewSizePreference.UseHalf);
                    });
}

Then in the OnNavigatedTo method and Loaded event:

private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    if (size != null)
    {
        var newwidth = Convert.ToInt32(size[0]) - 300;
        var newheight = Convert.ToInt32(size[1]) - 200;
        ApplicationView.GetForCurrentView().TryResizeView(new Size { Width = newwidth, Height = newwidth });
    }
}

private string[] size;

protected override void OnNavigatedTo(NavigationEventArgs e)

{
    if (e.Parameter.ToString() != "")
    {
        size = e.Parameter.ToString().Split(':');
    }
}

Or if you don't mind to see the resizing process of the new window, you can also try this code, and there is no need to send size as parameter to the new window in this method:

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

await ApplicationViewSwitcher.TryShowAsStandaloneAsync(
    newAppView.Id,
    ViewSizePreference.UseHalf,
    currentAV.Id,
    ViewSizePreference.UseHalf);
newAppView.TryResizeView(new Size { Width = rect.Width - 300, Height = rect.Height - 200 });
Grace Feng
  • 16,564
  • 2
  • 22
  • 45
  • It turns out the longer parameter method is not working but the shorter second option kind of works. I will need to study this further I guess. I am getting some undesirable side effects like multiple frames not going away and falling behind others etc. Today I am trying to get a Popup to do what I want but I can't slide it around the display. I am just trying to build a useful reference system that can be moved off of critical content. – Rick Aug 30 '16 at 14:25
  • It turns out that if I set`newAppView.TryResizeView(new Size { Width = 300, Height = 200 });` does not work, but use `rect.Width - 300`, why? How to set the new window a fixed size? – Vincent Mar 16 '20 at 09:37