Wpf从主屏幕开始

Nav*_*ani 5 .net c# wpf

如果用户有多个屏幕,

如何在启动时在主屏幕或所选屏幕中启动应用程序

bic*_*bic 8

继承人基本代码.它使用WinForms,但我不知道纯WPF解决方案.

using System;
using System.Windows;
using System.Windows.Forms;

namespace Foo
{
    public class WindowUtility
    {
        public static void MoveToMonitor(Window window, int monitorId, bool maximize)
        {
            Screen[] screens = Screen.AllScreens;

            int screenId = monitorId - 1;

            if (screens.Length > 1 && screenId < screens.Length)
            {
                var screen = screens[screenId];
                var area = screen.WorkingArea;

                if (maximize)
                {
                    window.Left = area.Left;
                    window.Top = area.Top;
                    window.Width = area.Width;
                    window.Height = area.Height;
                }
                else
                {
                    window.Left = area.Left;
                    window.Top = area.Top;
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)