TabControl.VerticalAlignment = 拉伸不执行任何操作
我正在尝试使 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>
上面的代码片段会生成以下窗口,而我希望红色边框到达窗口的底部:
I am trying to make a TabControl to auto resize according to the its outer space(it's in a 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>
The snippet above produces the following window, whilst I want the red border to reach the bottom of the window:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将高度绑定到父窗口的实际高度。
You can bind the height to parent window's actual height.
问题出在您的
StackPanel
上。 StackPanels 不会拉伸它们的孩子。相反,使用 DockPanel:最后一个子级将被拉伸以填充剩余空间(请参阅 LastChildFill,默认为
true
)。显式设置
VerticalAlignment
是不必要的,因为 其默认值已经是Stretch
。相关链接:MSDN 上的面板概述
The problem is your
StackPanel
. StackPanels won't stretch their children.Instead, use a
DockPanel
: The last child will be stretched to fill the remaining space (see LastChildFill, which defaults totrue
).Explicitly setting
VerticalAlignment
is not necessary, since its default value is alreadyStretch
.Related Link: Panels Overview on MSDN