[英]How to set a Window size to 0?
看來我無法將Window元素的Height屬性設置為0。對此有解釋嗎?
此代碼不起作用,也不在后面的代碼中將Height強制為0。 我的機器的ActualHeight始終返回14.0
<Window x:Class="AnimWindow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="0" Width="525" AllowsTransparency="True" WindowStyle="None" Background="YellowGreen" >
</Window>
提示表示贊賞。
編輯:對不起,忘了一個解釋:)我想創建某種通知彈出窗口,例如Outlook確實可以通知用戶。 盡管不透明效果很好,但將高度設置為動畫或將高度設置為0卻不可行。
好吧,我花了一些研究。 首先,這段代碼:
<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
一些鏈接:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.