主屏幕在虚拟屏幕中的位置
我可以将 wpf 窗口置于主屏幕或虚拟屏幕中的某个位置。但是,我想将窗口拉伸到整个虚拟屏幕上,并在窗口中放置一个网格,使其填充主屏幕。下面的截图显示了如何拉伸窗口、添加网格并拉伸网格以适合主屏幕尺寸,但如何确定网格的位置(即边距)?
<Window x:Class="BC.Citrium.Screensaver.Saver.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
Height="{x:Static SystemParameters.VirtualScreenHeight}"
Width="{x:Static SystemParameters.VirtualScreenWidth}"
Top="{x:Static SystemParameters.VirtualScreenTop}"
Left="{x:Static SystemParameters.VirtualScreenLeft}"
ResizeMode="NoResize" WindowStyle="None">
<Grid Name="mainGrid"
Height="{x:Static SystemParameters.MaximizedPrimaryScreenHeight}"
Width="{x:Static SystemParameters.MaximizedPrimaryScreenWidth}"
Margin="???"
Background="Bisque">
</Grid>
</Window>
我可以绘制两个窗口,一个适合虚拟屏幕,一个在上面适合主屏幕,但这不是好方法。
I can center a wpf window in somewhere in the primary screen or in the virtual screen. However, I want to stretch the window over the whole virtual screen and place e.g. a grid in the window in a way that it fills the primary screen. The following snipped shows how I stretch the window, add a grid and stretch the grid to fit the primary screen size, but how do I determine the position (i.e. margin) for the grid?
<Window x:Class="BC.Citrium.Screensaver.Saver.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
Height="{x:Static SystemParameters.VirtualScreenHeight}"
Width="{x:Static SystemParameters.VirtualScreenWidth}"
Top="{x:Static SystemParameters.VirtualScreenTop}"
Left="{x:Static SystemParameters.VirtualScreenLeft}"
ResizeMode="NoResize" WindowStyle="None">
<Grid Name="mainGrid"
Height="{x:Static SystemParameters.MaximizedPrimaryScreenHeight}"
Width="{x:Static SystemParameters.MaximizedPrimaryScreenWidth}"
Margin="???"
Background="Bisque">
</Grid>
</Window>
I could draw two windows, one to fit the virtual screen and one above that to fit the primary screen, but that's not the nice way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
主屏幕的左上角始终位于屏幕位置 (0, 0)。这使得您想要使用的边距(-VirtualScreenLeft、-VirtualScreenTop)。调整窗口边框宽度和窗口标题高度。
The upper left corner of the primary screen is always at screen position (0, 0). Which makes the margin you want to use (-VirtualScreenLeft, -VirtualScreenTop). With adjustment for the window border width and the window caption height.