我创建了这个简单的演示,因为在WPF中使自动调整大小工作起来有些困难。以下是简单的代码:
<Window x:Class="UnderstandSizing.Window3"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
SizeToContent="WidthAndHeight"
ResizeMode="NoResize" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TabControl Grid.Row="0" >
<TabItem Header="CCCC" />
</TabControl>
<Button Grid.Row="1" Content="Text" />
</Grid>
</Window>
作为网格布局的一部分,所有设置都是自动的,并且窗口被配置为 sizetocontent,我期望在窗口中只有TabControl和按钮,但实际上还有空白区域。请看以下图片:设计时和运行时。我肯定漏掉了什么……