private async void RequestAndStartProjecting_Click(object sender, RoutedEventArgs e)
        {
            // If projection is already in progress, then it could be shown on the monitor again
            // Otherwise, we need to create a new view to show the presentation
            if (rootPage.ProjectionViewPageControl == null)
            {
                // First, create a new, blank view
                var thisDispatcher = Window.Current.Dispatcher;
                await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    // ViewLifetimeControl is a wrapper to make sure the view is closed only
                    // when the app is done with it
                    rootPage.ProjectionViewPageControl = ViewLifetimeControl.CreateForCurrentView();

                    // Assemble some data necessary for the new page
                    var initData                       = new ProjectionViewPageInitializationData();
                    initData.MainDispatcher            = thisDispatcher;
                    initData.ProjectionViewPageControl = rootPage.ProjectionViewPageControl;
                    initData.MainViewId                = thisViewId;

                    // Display the page in the view. Note that the view will not become visible
                    // until "StartProjectingAsync" is called
                    var rootFrame = new Frame();
                    rootFrame.Navigate(typeof(ProjectionViewPage), initData);
                    Window.Current.Content = rootFrame;
                    Window.Current.Activate();
                });
            }

            try
            {
                // Start/StopViewInUse are used to signal that the app is interacting with the
                // view, so it shouldn't be closed yet, even if the user loses access to it
                rootPage.ProjectionViewPageControl.StartViewInUse();

                // Show the view on a second display (if available) or on the primary display
                Rect pickerLocation = new Rect(470.0, 0.0, 200.0, 300.0);
                await ProjectionManager.RequestStartProjectingAsync(rootPage.ProjectionViewPageControl.Id, thisViewId, pickerLocation, Windows.UI.Popups.Placement.Above);

                rootPage.ProjectionViewPageControl.StopViewInUse();

                rootPage.NotifyUser("Projection started with success", NotifyType.StatusMessage);
            }
            catch (InvalidOperationException)
            {
                rootPage.NotifyUser("The projection view is being disposed", NotifyType.ErrorMessage);
            }
        }
Exemplo n.º 2
0
        public async Task <int> RequestProjectAsync(Type viewType, Rect?position = null)
        {
            int mainViewId   = ApplicationView.GetForCurrentView().Id;
            int?secondViewId = null;

            var view = CoreApplication.CreateNewView();
            await view.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                secondViewId  = ApplicationView.GetForCurrentView().Id;
                var rootFrame = new Frame();
                rootFrame.Navigate(viewType, mainViewId);
                Window.Current.Content = rootFrame;
                Window.Current.Activate();
            });

            if (secondViewId.HasValue)
            {
                var defaultPosition = new Rect(0.0, 0.0, 200.0, 200.0);
                await ProjectionManager.RequestStartProjectingAsync(secondViewId.Value, mainViewId, position.HasValue?position.Value : defaultPosition);
            }

            return(mainViewId);
        }