Xamarin and UWP Secondary Window Sizing


I’m using the following code to launch a secondary window.

static async Task OpenSecondaryWindow(ContentPage contentPage) {
    var coreApplicationView  CoreApplication.CreateNewView();
    int viewId  0;
    await coreApplicationView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () > {
        var frame  new Windows.UI.Xaml.Controls.Frame();
        Window.Current.Content  frame;
        viewId  ApplicationView.GetForCurrentView().Id;
    bool viewShown  await ApplicationViewSwitcher.TryShowAsStandaloneAsync(viewId);

ContentPage is of the same class that’s instantiated and set to MainPage in my Xamarin.Forms.Application.

The problem I’m having is that when sizing the secondary window, the frame sizes, but not the content. What do I need to do to get the content to size as well?


This does the trick.

frame.SizeChanged + delegate (object sender, SizeChangedEventArgs e) {
    contentPage.Layout(new Rectangle(0, 0, e.NewSize.Width, e.NewSize.Height));

Answered By – Tim

Leave a Comment