Shi*_*mmy 8 wpf layout tabcontrol vertical-alignment
我正在尝试使TabControl根据其外部空间(它在StackPanel中)自动调整大小:
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="100">
<Grid>
<StackPanel>
<TabControl
BorderBrush="Red"
BorderThickness="2"
VerticalAlignment="Stretch"
VerticalContentAlignment="Stretch">
<TabItem Header="Tab1"/>
<TabItem Header="Tab2"/>
</TabControl>
</StackPanel>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
上面的代码片段生成以下窗口,同时我希望红色边框到达窗口的底部:
Hei*_*nzi 19
问题是你的StackPanel
.StackPanels不会伸展自己的孩子.
相反,使用DockPanel
:最后一个子项将被拉伸以填充剩余空间(请参阅LastChildFill,默认为true
).
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="100">
<Grid>
<DockPanel>
<TabControl BorderBrush="Red" BorderThickness="2">
<TabItem Header="Tab1"/>
<TabItem Header="Tab2"/>
</TabControl>
</DockPanel>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
VerticalAlignment
不需要显式设置,因为它的默认值已经是Stretch
.