简体   繁体   中英

How to automatically size TabControl in a DockPanel - WPF

I have a simple WPF Forms app. I have a DockPanel as my root panel. The first child is a StackPanel that has some controls in it, then the second control is a 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. However no matter what I try the TabControl seems to change its size depending on whats inside it, not whats it is inside of.

<Window>
    <DockPanel>
        <StackPanel> </StackPanel>
        <TabControl> </TabControl>
    </DockPanel>
</Window>

Just set the HorizontalAlignment and VerticalAlignment properties of your TabControl to "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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM