【发布时间】:2018-12-11 11:22:48
【问题描述】:
TL;DR
似乎将AllowTransparency 设置为True 会使窗口在最大化时向上和向左偏移8 个像素,我需要将其重新显示在屏幕上。
深入
看起来我在某处犯了错误,但不知道为什么。我无法发布整个代码,但我会尝试在这里写下所有相关的内容。
我有我的主窗口,它有一个自定义标题栏。这意味着我必须将WindowsStyle 设置为None,而且我还使用了模板。从一开始,我就遇到了窗口比我的桌面大得多的问题,同时最大化。它在所有方面都在屏幕外 8 像素。我放弃了模板并尝试更改现有窗口以满足我的需要。通过将AllowTransparency 设置回false,我设法消除了侧面的泄漏。然后出现的问题是窗口顶部的边框,我通过将WindowChrome 的CaptionHeight 设置为0 将其删除。
好的,泄漏消失了。但我相信我目前的问题与我上面写的有关。也就是说,我无法将宽度和高度绑定到某个东西,没有合适的属性。这是我从SystemParameters 尝试的:
SystemParameters.FullPrimaryScreenHeight;
SystemParameters.FullPrimaryScreenWidth;
SystemParameters.MaximizedPrimaryScreenHeight;
SystemParameters.MaximizedPrimaryScreenWidth;
SystemParameters.PrimaryScreenHeight;
SystemParameters.PrimaryScreenWidth;
SystemParameters.WorkArea.Height;
SystemParameters.WorkArea.Width;
SystemParameters.VirtualScreenWidth;
所需的实际高度 (1048) 介于 SystemParameters.WorkArea.Height (1040) 和 SystemParameters.MaximizedPrimaryScreenHeight (1056) 之间。
所需的实际宽度 (1928) 介于 SystemParameters.WorkArea.Width (1920) 和 SystemParameters.MaximizedPrimaryScreenWidth (1936) 之间。
你可以在这里看到模式。
- MaximizedPrimaryScreenWidth 和 MaximizedPrimaryScreenHeight 都比我需要的大了 8 个像素
- WorkArea.Width 和 WorkArea.Height 都比我需要的小了 8 个像素
- 之前我的四面都漏了 8 个像素
这是我的窗口代码
<Window x:Class="MyApp.MainWindow"
...
WindowState="Normal"
ResizeMode="CanResizeWithGrip"
MaxHeight="{Binding SystemParameters.WorkArea.Height}"
WindowStyle="None">
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="0"/>
</WindowChrome.WindowChrome>
....content....
</Window>
什么也不起作用:
- Window.Padding
- Window.Margin
- Window.Top
- WindowStyle="SingleBorderWindow"
我拥有但不想要的东西
XAML:
MaxWidth="{Binding MaximumWidth}"
C#
public double MaximumWidth
{
get
{
// I don't want anything hard-coded.
// Some other (correct) parameter would be fine as well,
// if we can't get the window on screen.
return SystemParameters.WorkArea.Width + 8;
}
}
更新:SingleBorderWindow
这是使用WindowStyle="SingleBorderWindow" 时发生的情况。
因此,我的窗口不仅比我的右边缘和下边缘短 8 像素(绑定到 WorkArea 时),而且您可以看到后面的实际窗口并且按钮是可点击的(即使它们不可见)。真奇怪。就像有两个窗口,但我需要的只有一个不在正确的位置。
【问题讨论】:
-
无法复制。尝试从头开始构建一个示例,您会看到哪个自定义功能打破了您的窗口。
标签: c# wpf xaml window fullscreen