Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF ListBox scrollbar is not working

<ListBox Name="myListBx" ItemsSource="{Binding Collection}" Margin="5,5"
    SelectedValuePath="ColId"
    SelectedValue="{Binding Path=ColId}"
    SelectionMode="Multiple"
    BorderThickness="0" Background="{x:Null}" BorderBrush="{x:Null}"
    ScrollViewer.VerticalScrollBarVisibility ="Auto">
    <ListBox.ItemTemplate>
        <DataTemplate>
            // blabla
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

My ListBox contains so many elements and actually the scrollbar should work but it's not even visible. Am I doing something wrong?

Thanks

like image 314
Stacked Avatar asked Mar 28 '26 11:03

Stacked


1 Answers

You need to put the ListBox in a Grid. The StackPanel has an
infinite height, so that the ScrollBar does not get enabled or visible.

<Grid>
  <ListBox VerticalAlignment="Stretch" />
</Grid>
like image 133
Jehof Avatar answered Mar 29 '26 23:03

Jehof



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!