我的Windows 11系统有两个显示器:
- 一台扩展系数为150%的4k显示器,
- 一台比例系数为100%的全高清显示器(当然,这也需要与不同的系统设置配合使用)
我想在另一台显示器上显示一个新的WPF窗口--这意味着在我的主应用程序当前没有显示的显示器上.因此,如果我的主窗口在4k显示器上,那么我想在全高清显示器上显示新窗口.
新的窗口应该会显示我的网络摄像头的全屏视图.但是,由于DPI设置不同,因此很难以正确的位置和大小显示全屏窗口.
我的窗口XAML是直接的,如下所示
<Window
x:Class="MyApp.Fullscreen"
x:ClassModifier="internal"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="800"
Height="600"
AllowsTransparency="False"
Background="Black"
ResizeMode="NoResize"
ShowInTaskbar="False"
Topmost="True"
WindowStyle="None">
<Grid>
<Image Name="WebCam" />
</Grid>
</Window>
我是这样初始化它的
var allSystemScreens = System.Windows.Forms.Screen.AllScreens;
var otherScreen = DetermineOtherScreen(allSystemScreens);
var window = new Fullscreen();
window.WindowStartupLocation = WindowStartupLocation.Manual;
window.Left = otherScreen.WorkingArea.Left;
window.Top = otherScreen.WorkingArea.Top;
window.Width = otherScreen.WorkingArea.Width;
window.Height = otherScreen.WorkingArea.Height;
window.Show();
但这并不管用.它没有在显示器上完全显示窗口,或者比显示器大得多,正在伸手到第二个显示器上.
我研究了WorkingArea中的值.但它从来都不管用.
My app is DPI per-monitor-aware.我试图应用scale factor that I read from the system,但无论我使用什么值-它从来没有正确的位置或大小.
如何正确地做好这件事?或者,有没有更容易或更好的方法来实现这一点?也许不用用WindowStartupLocation.Manual
美元.