Open new window on secondary monitor in UWP

跟風遠走 提交于 2021-01-27 06:24:11

问题


I have a UWP project with two monitors that I want to use to open a new window on a secondary monitor. The application includes three parts:

  1. Open Main Page on first monitor
  2. Create new page
  3. Open on secondary monitor

I wrote the first and second parts correctly, but I can't find a solution for the third part.

Please help me with moving the window to another monitor.

public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();

      //called creat new page function
        NewWindow();
    }

    private async void NewWindow()
    {
        var myview = CoreApplication.CreateNewView();
        int newid = 0;
        await myview.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
        {
            Frame newframe = new Frame();
            newframe.Navigate(typeof(Newpage), null);

            Window.Current.Content = newframe;
            Window.Current.Activate();
            ApplicationView.GetForCurrentView().Title = "Z";

            newid = ApplicationView.GetForCurrentView().Id;
        });

        await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newid, ViewSizePreference.UseMinimum);

    }

}

回答1:


As @Ehssan's suggestion, the ProjectionManager Class meets your requirement. When you create a new view, you could use ProjectionManager.StartProjectingAsync Method to send it to the projector or other secondary display.

You could see the official Projection sample for more information.




回答2:


I found the solution and used ProjectionManger Class.

 private async void expand()
    {
        var NewWindow = CoreApplication.CreateNewView();
        int Windowid = ApplicationView.GetForCurrentView().Id;
        int NewWindowid = 0;

        await NewWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
        {
            Frame newframe = new Frame();
            newframe.Navigate(typeof(Newpage), null);

            Window.Current.Content = newframe;
            Window.Current.Activate();
            ApplicationView.GetForCurrentView().Title = "New Page";

            NewWindowid = ApplicationView.GetForCurrentView().Id;
        });

        //Call ProjectionManager class for moving new window to secodary display
        bool available = ProjectionManager.ProjectionDisplayAvailable;

        ProjectionManager.ProjectionDisplayAvailableChanged += (s, e) =>
        {
            available = ProjectionManager.ProjectionDisplayAvailable;
        };

        await ProjectionManager.StartProjectingAsync(NewWindowid, Windowid);
    }



回答3:


This might help your for identifying monitors.

this.Location = Screen.AllScreens[1].WorkingArea.Location;


来源:https://stackoverflow.com/questions/53923498/open-new-window-on-secondary-monitor-in-uwp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!