0

I have the following wpf Window. Why the StackPanel is not taking the size of the GroupBox ? How Can I force it to auto take the size of the GroupBox ?

Thank you

XAML

  <Window
        

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:local="clr-namespace:StyleTrigger"
            xmlns:local2="clr-namespace:ComboBoxData"
            xmlns:sys="clr-namespace:System;assembly=mscorlib"
            xmlns:ig="http://schemas.infragistics.com/xaml" x:Class="StyleTrigger.MainWindow"
            mc:Ignorable="d"
            Title="MainWindow" Height="350" Width="525">
    
    
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="50*" />
                <ColumnDefinition Width="50*"/>
            </Grid.ColumnDefinitions>
    
    
            <Grid.RowDefinitions>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="1*"/>
            </Grid.RowDefinitions>
    
            <GroupBox x:Name="groupBox" Header="GroupBox" Grid.Row="1"  >
                <StackPanel  HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                    <TextBox />
                    <TextBox />
                </StackPanel>
            </GroupBox>
    
        </Grid>
    </Window>
Community
  • 1
  • 1
TheOne
  • 157
  • 16
  • Are you sure that is the stack panel not taking the size of the group box? or is the group box not adapting? – Jose Jul 04 '16 at 13:00
  • Is it too big (there is whitespace around the content) or too small (the content is clipped or there are scrollbars)? – ChrisF Jul 04 '16 at 13:01
  • You need to use either `DockPanel` or `Grid`, [Check this relevant answer](http://stackoverflow.com/a/569275/352101) – Bolu Jul 04 '16 at 13:07
  • kirenenko: GroupBox Height = 106 & StackPanel Height=84 – TheOne Jul 04 '16 at 13:27
  • 106-84 seems to be the height of the GroupBox header plus the internal border size. Take a look at it in the XAML Designer in VisualStudio. – Clemens Jul 04 '16 at 13:33
  • Bolu: It is the same issue with a Grid. – TheOne Jul 04 '16 at 13:34
  • I just copied and pasted your code and the stack panel and textboxes inside are stretched properly, they all take all available space (1 row and 1 column). – adminSoftDK Jul 04 '16 at 13:44
  • adminSoftDK: If you click on the StackPanel inside the GroupBox you view its height property, you would be able to see the both heights are not the same. I'm not sure how see the boarder height so I can do the math. – TheOne Jul 04 '16 at 14:21

0 Answers0