C# 辅助监视器上的显示窗口

C# 辅助监视器上的显示窗口,c#,wpf,C#,Wpf,我想在辅助监视器上显示一个窗口,如下所示: Queue<string> itemQueue = new Queue<string>(); MonitorWindow monitor = new MonitorWindow(itemQueue); var secondaryScreen = System.Windows.Forms.Screen.AllScreens.Where(s => !s.Primary)

我想在辅助监视器上显示一个窗口,如下所示:

Queue<string> itemQueue = new Queue<string>();

MonitorWindow monitor = new MonitorWindow(itemQueue);

var secondaryScreen = System.Windows.Forms.Screen.AllScreens.Where(s => !s.Primary)
                                                            .FirstOrDefault();

if (secondaryScreen != null)
{
     monitor.WindowStartupLocation = WindowStartupLocation.Manual;
     var workingArea = secondaryScreen.WorkingArea;
     monitor.Left = workingArea.Left;
     monitor.Top = workingArea.Top;
     monitor.Width = workingArea.Width;
     monitor.Height = workingArea.Height;
     monitor.Show();

}
        Queue<string> itemQueue = new Queue<string>();

        MonitorWindow monitor = new MonitorWindow(itemQueue);

        var secondaryScreen = System.Windows.Forms.Screen.AllScreens.Where(s => !s.Primary).FirstOrDefault();

        if (secondaryScreen != null)
        {
            if (!monitor.IsLoaded)
                monitor.WindowStartupLocation = WindowStartupLocation.Manual;
            var workingArea = secondaryScreen.WorkingArea;
            monitor.Left = workingArea.Left;
            monitor.Top = workingArea.Top;
            monitor.Width = workingArea.Width;
            monitor.Height = workingArea.Height;
            // If window isn't loaded then maxmizing will result in the window displaying on the primary monitor
            monitor.Show();
            if (monitor.IsLoaded)
                monitor.WindowState = WindowState.Maximized;
        }
Queue itemQueue=new Queue();
MonitorWindow monitor=新的MonitorWindow(itemQueue);
var secondaryScreen=System.Windows.Forms.Screen.AllScreens.Where(s=>!s.Primary)
.FirstOrDefault();
如果(第二屏幕!=null)
{
monitor.WindowStartupLocation=WindowStartupLocation.Manual;
var workingArea=第二屏幕。workingArea;
监视器左=工作区域左;
monitor.Top=工作区域Top;
监视器宽度=工作区域宽度;
监视器高度=工作区域高度;
monitor.Show();
}

属性具有正确的值,但这会使主监视器上的窗口最大化。您能帮助我吗?

好的,我已经修复了在MonitorWindow的XAML代码中删除属性WindowState=“Maximized”的问题,并按如下方式更改了程序:

Queue<string> itemQueue = new Queue<string>();

MonitorWindow monitor = new MonitorWindow(itemQueue);

var secondaryScreen = System.Windows.Forms.Screen.AllScreens.Where(s => !s.Primary)
                                                            .FirstOrDefault();

if (secondaryScreen != null)
{
     monitor.WindowStartupLocation = WindowStartupLocation.Manual;
     var workingArea = secondaryScreen.WorkingArea;
     monitor.Left = workingArea.Left;
     monitor.Top = workingArea.Top;
     monitor.Width = workingArea.Width;
     monitor.Height = workingArea.Height;
     monitor.Show();

}
        Queue<string> itemQueue = new Queue<string>();

        MonitorWindow monitor = new MonitorWindow(itemQueue);

        var secondaryScreen = System.Windows.Forms.Screen.AllScreens.Where(s => !s.Primary).FirstOrDefault();

        if (secondaryScreen != null)
        {
            if (!monitor.IsLoaded)
                monitor.WindowStartupLocation = WindowStartupLocation.Manual;
            var workingArea = secondaryScreen.WorkingArea;
            monitor.Left = workingArea.Left;
            monitor.Top = workingArea.Top;
            monitor.Width = workingArea.Width;
            monitor.Height = workingArea.Height;
            // If window isn't loaded then maxmizing will result in the window displaying on the primary monitor
            monitor.Show();
            if (monitor.IsLoaded)
                monitor.WindowState = WindowState.Maximized;
        }
Queue itemQueue=new Queue();
MonitorWindow monitor=新的MonitorWindow(itemQueue);
var secondaryScreen=System.Windows.Forms.Screen.AllScreens.Where(s=>!s.Primary.FirstOrDefault();
如果(第二屏幕!=null)
{
如果(!monitor.IsLoaded)
monitor.WindowStartupLocation=WindowStartupLocation.Manual;
var workingArea=第二屏幕。workingArea;
监视器左=工作区域左;
monitor.Top=工作区域Top;
监视器宽度=工作区域宽度;
监视器高度=工作区域高度;
//如果未加载窗口,则最大化将导致窗口显示在主监视器上
monitor.Show();
如果(监视器已加载)
monitor.WindowState=WindowState.Maximized;
}

您确定没有混淆主监视器和辅助监视器吗?因为我看不出你的示例代码有什么问题……当用户有两个以上的监视器时会发生什么?你只是随便挑一个-(另外,如果您希望窗口最大化,您应该使其最大化。不要通过设置窗口坐标来模拟最大化。@ChrFin是的,我确定!我已经检查了很多次:-(!@CodyGray我的应用程序不是通用的,将用于特定用途!用户没有两个以上的监视器!同时,我已经设置了WindowState=“maximized”在xaml代码中!