WPF ListBox scrollbar is not working

旧街凉风 提交于 2019-12-24 02:24:32

问题


<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


回答1:


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>


来源:https://stackoverflow.com/questions/15294112/wpf-listbox-scrollbar-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!