WPF ListBox滚动条不起作用 [英] WPF ListBox scrollbar is not working

查看:1086
本文介绍了WPF ListBox滚动条不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<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>

我的ListBox包含许多元素,实际上滚动条应该可以工作,但它甚至不可见. 我在做错什么吗?

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

谢谢

推荐答案

您需要将ListBox放入网格中. StackPanel具有一个
无限的高度,以使ScrollBar不会启用或可见.

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>

这篇关于WPF ListBox滚动条不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆