gpt4 book ai didi

wpf - TabControl.VerticalAlignment = 拉伸(stretch)不做任何事情

转载 作者:行者123 更新时间:2023-12-04 04:58:26 26 4
gpt4 key购买 nike

我正在尝试使 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>

上面的代码片段产生以下窗口,而我希望红色边框到达窗口的底部:

alt text

最佳答案

问题是你的StackPanel . StackPanels 不会拉伸(stretch)他们的 child 。

相反,请使用 DockPanel :最后一个 child 将被拉伸(stretch)以填充剩余空间(参见 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>

显式设置 VerticalAlignment没有必要,因为 its default value已经是 Stretch .

相关链接: Panels Overview on MSDN

关于wpf - TabControl.VerticalAlignment = 拉伸(stretch)不做任何事情,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1967013/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com