/
SecondaryWindowService.cs
36 lines (33 loc) · 1.13 KB
/
SecondaryWindowService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Threading.Tasks;
using Windows.ApplicationModel.Core;
using Windows.UI.Core;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Xamarin.Forms;
using Xamarin.Forms.ControlGallery.WindowsUniversal;
using Xamarin.Forms.Controls;
using Xamarin.Forms.Platform.UWP;
[assembly: Dependency(typeof(SecondaryWindowService))]
namespace Xamarin.Forms.ControlGallery.WindowsUniversal
{
class SecondaryWindowService : ISecondaryWindowService
{
public async Task OpenSecondaryWindow(Type pageType)
{
CoreApplicationView newView = CoreApplication.CreateNewView();
int newViewId = 0;
await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
var frame = new Windows.UI.Xaml.Controls.Frame();
//The page instance must be created inside the new UI Thread.
ContentPage instance = (ContentPage)Activator.CreateInstance(pageType);
frame.Navigate(instance);
Window.Current.Content = frame;
Window.Current.Activate();
newViewId = ApplicationView.GetForCurrentView().Id;
});
bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
}
}
}