[英]How to automatically size TabControl in a DockPanel - WPF
I have a simple WPF Forms app. 我有一个简单的WPF表单应用程序。 I have a DockPanel as my root panel. 我有一个DockPanel作为我的根面板。 The first child is a StackPanel that has some controls in it, then the second control is a TabControl. 第一个孩子是其中包含一些控件的StackPanel,然后第二个控件是TabControl。 What I want, and the panel types can change all they want is for the TabControl to maintain the fill size of the window except for what the first StackPanel consumes. 我想要的是,面板类型可以更改所需的所有内容,这是TabControl保持窗口填充大小的原因,除了第一个StackPanel消耗的内容。 However no matter what I try the TabControl seems to change its size depending on whats inside it, not whats it is inside of. 但是,无论我尝试什么,TabControl似乎都会根据其内部内容(而不是内部内容)更改其大小。
<Window>
<DockPanel>
<StackPanel> </StackPanel>
<TabControl> </TabControl>
</DockPanel>
</Window>
Just set the HorizontalAlignment and VerticalAlignment properties of your TabControl to "Stretch": 只需将TabControl的HorizontalAlignment和VerticalAlignment属性设置为“ Stretch”:
<DockPanel>
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" Margin="5">
<TextBlock Text="Hello" />
<TextBlock Text="World" />
</StackPanel>
<TabControl HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<TabItem Header="Small">
<TextBlock Text="Just Some Small Stuff" />
</TabItem>
<TabItem Header="Bigger">
<StackPanel>
<TextBlock Text="One line" />
<TextBlock Text="The next line" />
</StackPanel>
</TabItem>
</TabControl>
</DockPanel>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.