3

I'm trying to implement an expander in WPF which in side there are some nested controls. One of these is a Wrap Panel which i'd like to wrap as the user changes the window size.

This works if i take the Grid Control parent of the WrapPanel out and put it in its own App but not in this format. As i'm not using minimum width for this Grid it suprises me why it doesnt wrap. Any ideas? Thanks

<Window x:Class="WpfApplication5.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525" FontFamily="Calibri" FontSize="8">
<StackPanel Orientation="Vertical">
    <Expander Margin="3" Padding="3">
        <Expander.Header>
            <StackPanel Orientation="Horizontal" MinWidth="150" Width="Auto" MinHeight="25">
                <Label MinWidth="50">Label 1</Label>
                <CheckBox VerticalAlignment="Center"></CheckBox>
                <Border></Border>
                <Label>Label 2</Label>
            </StackPanel>
        </Expander.Header>
        <Expander.Content>
            <StackPanel Orientation="Horizontal" >
                <Label MinWidth="150">Add Image</Label>
                <Grid Name="Grid1"  ShowGridLines="True" Width="Auto">
                    <Grid.RowDefinitions>
                        <RowDefinition Name="Title1" MinHeight="25"></RowDefinition>
                        <RowDefinition Name="Number1" MinHeight="25"></RowDefinition>
                        <RowDefinition Name="PlaneA" MinHeight="25"></RowDefinition>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Name="Plane1" MinWidth="25" Width="Auto"></ColumnDefinition>
                        <ColumnDefinition Name="PlaneCheckBox" MinWidth="25" Width="Auto"></ColumnDefinition>
                        <ColumnDefinition Name="Border1" MinWidth="25" Width="Auto"></ColumnDefinition>
                        <ColumnDefinition Name="List1" Width="*"></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <WrapPanel Grid.Row="2" Grid.Column="3" Orientation="Horizontal" VerticalAlignment="Stretch">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition MinWidth="25"></ColumnDefinition>
                                <ColumnDefinition MinWidth="25"></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <CheckBox Grid.Column="0" VerticalAlignment="Center"></CheckBox>
                            <Label Grid.Column="1">No. 1</Label>
                        </Grid>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition MinWidth="25"></ColumnDefinition>
                                <ColumnDefinition MinWidth="25"></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <CheckBox Grid.Column="0" VerticalAlignment="Center"></CheckBox>
                            <Label Grid.Column="1">No. 1</Label>
                        </Grid>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition MinWidth="25"></ColumnDefinition>
                                <ColumnDefinition MinWidth="25"></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <CheckBox Grid.Column="0" VerticalAlignment="Center"></CheckBox>
                            <Label Grid.Column="1">No. 1</Label>
                        </Grid>
                    </WrapPanel>
                </Grid>
            </StackPanel>
        </Expander.Content>
    </Expander>
</StackPanel>

gwizardry
  • 501
  • 1
  • 6
  • 19

1 Answers1

0

StackPanel has an infinite size in the orientation direction. so when using a WrapPanel inside a StackPanel you must limit the size of the StackPanel in that direction. Grid has a finite size on the other hand, so you can see your content wrapping.

stsur
  • 206
  • 2
  • 9