wpf TabControl 宽度高度问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11899160/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 04:56:22  来源:igfitidea点击:

TabControl Width Height issue

wpfsizeheightwidthtabcontrol

提问by Floc

I'm using a TabControl with no Height and Width specified. Actually, the height of the TabControl take the height of the current tab.

我正在使用没有指定高度和宽度的 TabControl。实际上,TabControl 的高度取当前选项卡的高度。

I don't want the TabControl auto adjust it size. I want it take the size (Heigth and Width) of the biggest tab.

我不希望 TabControl 自动调整它的大小。我希望它采用最大标签的大小(高度和宽度)。

How can I do that ?

我怎样才能做到这一点 ?

Thanks.

谢谢。

采纳答案by Dan Puzey

The size of your TabControlwill be being set by its parentcontainer control, which is responsible for the layout of its children, and will specify default values for many layout properties.

您的尺寸TabControl将由其父容器控件设置,该控件负责其子项的布局,并将为许多布局属性指定默认值。

If, for example, you place the TabControlinside a (vertical) StackPanel, you'll find that it takes the minimum vertical space that it can. If you have a Gridaround your tabs, they'll fill the available space.

例如,如果您将TabControla (vertical)放在里面StackPanel,您会发现它占用的垂直空间最小。如果您Grid的标签周围有一个,它们将填满可用空间。

Alternatively, you can manually set VerticalAlignment="Top"with other containers, and this will typically override the behaviour you're seeing. (Most likely your layout panel is defaulting this to Stretch.)

或者,您可以VerticalAlignment="Top"使用其他容器手动设置,这通常会覆盖您看到的行为。(很可能您的布局面板将其默认为Stretch。)

回答by Eplebit

Because some people asked for the actual xaml, here is something that worked for me. It is based on the tips from @FWillem, @Floc and the others, so all credit goes to them.

因为有些人要求提供实际的 xaml,所以这里有一些对我有用的东西。它基于@FWillem、@Floc 和其他人的提示,因此所有功劳都归功于他们。

<TabControl>
    <TabItem Header="SomeTab1">
        <Grid Name="MasterTabGrid">
            <!-- Some content -->
        </Grid>
    </TabItem>
    <TabItem Header="SomeTab2">
        <Grid Height="{Binding ElementName=MasterTabGrid, Path=ActualHeight}" >
            <!-- Some other content -->
        </Grid>
    </TabItem>
</TabControl>