こんにちは!
皆さんに迷惑をかけたくないのですが、WPF のウィンドウの「高さ」プロパティに「自動」値がある場合、ほとんど疑問がありません。ここで物事がどのように機能するかを理解したいからです。XAML コードは次のとおりです。
<Window x:Class="WpfTest.MainWindow"
x:Name="window"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Collapsed and Hidden buttons comparison" Width="500">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<StackPanel Height="50" Grid.Column="0" Margin="5,0">
<Button Visibility="Collapsed">This is collapsed button</Button>
<Button >Below collapsed button</Button>
</StackPanel>
<StackPanel Height="50" Grid.Column="1" Margin="5,0">
<Button Visibility="Hidden">This is hidden button</Button>
<Button >Below hidden button</Button>
</StackPanel>
</Grid>
</Window>
次のような明示的な高さを使用する場合:
Height="300"
また
SizeToContent="WidthAndHeight"
幅の前はすべて完璧ですが、デフォルトの高さを入力したり削除したりしないと、ウィンドウはこの奇妙な外観になります。
プロパティの「高さ」の値は「自動」です。手続き型コードを使用して actualHeight を取得すると、526 になります。
MessageBox.Show(Convert.ToString(window.Height),"Height of the window");
ウィンドウがこのように動作する理由を誰かが説明できますか (つまり、ウィンドウが高さを取得する場所から)。前もって感謝します。