【发布时间】:2012-02-24 08:26:25
【问题描述】:
我创建了这个简单的演示,因为在 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>
由于网格将所有内容都设置为 Auto,并且窗口配置为 sizetocontent,我希望在窗口中有 TabControl 和按钮,但没有其他内容,但上面有空格。看:
设计时
运行时
我一定是错过了什么……
【问题讨论】:
-
您列出了您的 WPF 示例正在做什么,但我不清楚您期望什么行为。您能否告诉我们您的期望,以便我们为您指明正确的方向? NVM 我在问题中看到了细节......
-
我怀疑它只是为实际的 TabItem 保留空间。在 TabItem 中放置一个 TextBox。现在你只有一个 Header。
-
至于宽度,我怀疑边框标题区域占用了那么多空间。
标签: .net wpf resize sizetocontent