好吧,我花了一点研究。首先,这段代码:
<Window x:Class="ZeroHwindow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="0" Width="525"
WindowStyle="None"
AllowsTransparency="True"
Background="Yellow" />
返回 的高度值6,因为您有14。我在 上运行此代码Windows XP,我怀疑您有不同的操作系统。接下来我在 中设置参数ResizeMode,NoResize得到高度 2。
如果您设置ResizeMode="CanResizeWithGrip",我们将获得多达 17 个像素,这将适合Grip. 因此,我们看到系统本身插入了标准元素,即使参数是:WindowStyle="None", AllowsTransparency="True".
我也试过设置参数:ShowInTaskbar = False, ShowActivated = False, 无济于事,窗口不可见,但高度为2(结果有些人不相信这些参数,实际上高度/宽度不为零)。
顺便说一句,我忘了提:我在
ContentRendered="Window_ContentRendered"
像那样:
private void Window_ContentRendered(object sender, EventArgs e)
{
MessageBox.Show(this.Height.ToString());
MessageBox.Show(this.ActualHeight.ToString());
}
只是试图设置SizeToContent = WidthAndHeight:相同的高度 - 2,但Window不可见。
唯一有帮助的,它:
private void Window_ContentRendered(object sender, EventArgs e)
{
this.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
this.Arrange(new Rect(0, 0, 0, 0));
MessageBox.Show(this.Height.ToString());
MessageBox.Show(this.ActualHeight.ToString());
}
在这种情况下, ActualHeight 返回0。
也许画了一个标准的元素,是不可能得到的0。我也尝试设置Styles / Templates,但高度没有设置为零。原则上,正如预期的那样,它肯定是在系统级别设置的。
还是决定通过Snoop.
Part #1. Standard state

可以看到局部值设置的很高。
Part #2. Using Arrange and Measure

一些链接:
UIElement.Arrange
UIElement.Measure