如何在辅助显示中设置WPF窗口位置

我有两个显示器。 我想制作一个媒体播放器,我想在我的辅助显示器上全屏播放video。 所以我正在尝试使用WPF制作媒体播放器

这是我写的代码到目前为止

Screen[] _screens = Screen.AllScreens; System.Drawing.Rectangle ractagle = _screens[1].Bounds; //player is my window player.WindowState = WindowState.Maximized; player.WindowStyle = WindowStyle.None; player.Left = ractagle.X; player.Top = ractagle.Y; // MediaControl is an media elements MediaControl.Height = ractagle.Height; MediaControl.Width = ractagle.Width; 

但不知何故,它只是在我的第一个显示器上播放。 非常感谢任何forms的帮助。

您需要确保将WindowStartupLocation设置为Manual ,以显示您正在显示的表单

否则,你所做的一切都不会对窗户的位置产生任何影响。

 using System.Windows.Forms; // reference System.Drawing // Screen s = Screen.AllScreens()[1]; System.Drawing.Rectangle r = s.WorkingArea(); Me.Top = r.Top; Me.Left = r.Left; 

我使用的Window的XAML标题。

   //Controls etc   

5年后! 但对于其他人来说,我偶然发现了……

如果你不能或不想添加整个System.Windows.Forms dll引用,你可以使用micden的WpfScreenHelper (在NuGet中搜索)

  Screen screen = WpfScreenHelper.AllScreens[0]; Left = screen.Bounds.Left; Top = screen.Bounds.Top; Width = screen.Bounds.Width; Height = screen.Bounds.Height; 

Micdenny已经为WPF移植了Windows Forms Screen帮助程序。 当你有其他WPF引用不能很好地使用Forms(如WPF Live-Charts)时,这是非常好的。