views:

226

answers:

1

Hell, 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:

alt text

+1  A: 

The problem is your StackPanel. StackPanels won't stretch their children.

Instead, use a DockPanel:

<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>

Explicitly setting VerticalAlignment is not necessary, since its default value is already Stretch.

Related Link: Panels Overview on MSDN

Heinzi
I used your code, nothing; the TabControl's Vertical size is not docked as expected; I would think the problem is with the TabControl rather than the StackPanel.
Shimmy
Very strange... it works perfectly fine over here: I copy-and-paste the above code in a XAML window -> the red border stretches across the whole window. Could you try again?
Heinzi
Well your solution does work. Unfortunately based on the sircumstances of my windows that there are various parent it didn't work out. The solution to my particular problem was embedding it in a Grid setting the row's height to *.Thanks for all your help.
Shimmy