How to automatically size TabControl in DockPanel - WPF

I have a simple WPF Forms application. I have a DockPanel as my root panel. The first child is the StackPanel, which has some controls, and the second control is the TabControl. I want, and panel types can change everything they need for TabControl to maintain the fill size of the window, except that it consumes the first StackPanel. However, no matter what I try, TabControl seems to change its size depending on what is inside it and not inside.

<Window> <DockPanel> <StackPanel> </StackPanel> <TabControl> </TabControl> </DockPanel> </Window> 
+2
source share
1 answer

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

All Articles