ListBox

May 1, 2013 at 4:51 AM
This is interesting, but I dont know if its a problem. If I use the listbox in a gridview, then the scrollbars show, however if I use the listbox in a wrapanel or stackpanel, the scrollbar does not show.

grid view xaml:
       <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <TextBlock Text="Available" Grid.Row="0" Margin="0,10,0,10" HorizontalAlignment="Center" Grid.ColumnSpan="2" />
            <ListBox    Grid.Row="1"        
                        ScrollViewer.CanContentScroll="True" 
                        ScrollViewer.VerticalScrollBarVisibility="Visible" 
                        ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                        ItemsSource="{Binding   AccountsAvailable, 
                                                Mode=TwoWay, 
                                                NotifyOnTargetUpdated=True, 
                                                NotifyOnSourceUpdated=True}" 
                        SelectedValuePath="Id" >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Vertical">
                            <TextBlock Text="{Binding Id}" FontWeight="SemiBold" />
                            <TextBlock Text="{Binding Name}" />
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>
Stackpanel:
        <StackPanel Orientation="Vertical" >
            <TextBlock Text="Available" Margin="0,10,0,10" HorizontalAlignment="Center" />
            <ListBox    
                        ScrollViewer.CanContentScroll="True" 
                        ScrollViewer.VerticalScrollBarVisibility="Visible" 
                        ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                        ItemsSource="{Binding   AccountsAvailable, 
                                                Mode=TwoWay, 
                                                NotifyOnTargetUpdated=True, 
                                                NotifyOnSourceUpdated=True}" 
                        SelectedValuePath="Id" >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Vertical">
                            <TextBlock Text="{Binding Id}" FontWeight="SemiBold" />
                            <TextBlock Text="{Binding Name}" />
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </StackPanel>
Would you know why that happens ?
Coordinator
May 1, 2013 at 5:08 PM
By definition a StackPanel stretches to whatever size is required for its children. This is the nature of the StackPanel.