tags:

views:

686

answers:

2

Hi, I have a WPF ListBox control. It can have a long list of items.

When i am working with the normal screen resolution i.e 1024 * 768, it shows the listbox with scrollbar properly, if I mention the MinHeight and MaxHeight for the listbox.

and when I switch to another resolution, which is 1280 * 1024, ideally, the listbox should fit to the screen resolution. but, it is not happening. Due to the height, which i had mentioned, it remains the same, leaving a lot of a empty space down, which obviously does not look good.

and I need a scrollbar for normal 1024*768 resolution, so i must put MinHeight and MaxHeight.

Is there any solution, to view the extended ListBox which occupies the space properly for higher resolutions?

Thanks

+1  A: 

Use panels to lay out your controls - don't use explicit widths and heights. For example:

<Grid>
    <Grid.RowDefinitions>
        <Row Height="*"/>
        <Row Height="Auto"/>
    </Grid.RowDefinitions>

    <!-- ListBox will take up all remaining space after the Button -->
    <ListBox/>
    <!-- Button will take up only the space it needs -->
    <Button Grid.Row="1"/>
</Grid>

HTH, Kent

Kent Boogaart
A: 

                <StackPanel Orientation="Horizontal"  Margin="0,0,0,5" VerticalAlignment="Top" HorizontalAlignment="Left" Grid.Row="0">
                    <Label  FontWeight="Bold" FontSize="11" HorizontalAlignment="Left" Margin="0,0,5,5">Term:</Label>
                    <ComboBox x:Name="Term" Margin="0,5,5,0">
                    </ComboBox>                        
                </StackPanel>
                <CheckBox Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Top" x:Name="displaySummaryCheckBox" Margin="2,2,0,5"  FontSize="11" Content="Display Summary" IsChecked="True" FontWeight="Normal"></CheckBox>

            </Grid>                
            <Grid DockPanel.Dock="Bottom">

                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <Label Grid.Row="0" VerticalAlignment="Top" Margin="0,0,0,4" HorizontalAlignment="Left" FontWeight="Bold" FontSize="11">Display Columns</Label>
                    <ListBox Grid.Row="1" VerticalAlignment="Top" Margin="5,0,5,4" HorizontalAlignment="Left" x:Name="columnsList" Width="197"  FontSize="11">

                    </ListBox>
                    <Button Grid.Row="2"  Margin="5,0,5,2" HorizontalAlignment="Left" VerticalAlignment="Top" x:Name="selectAll" Width="75" Content="Select All" FontWeight="Normal"  FontSize="11" Height="23" Click="selectAll_Click"/>
                </Grid>

            </Grid>

        </DockPanel>
This is the code which i am working with
The row containing the ListBox will auto-size. That means it'll only be as big as the ListBox asks it to be. See my post for a solution.
Kent Boogaart