2013-03-08 109 views
2
<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包含如此多的元素,實際上滾動條應該可以工作,但它甚至不可見。 我做錯了什麼?WPF ListBox滾動條不起作用

謝謝

+2

什麼是ListBox的父容器(Grid,Stackpanel,...)? – Jehof 2013-03-08 12:45:43

+0

@Jehof這是一個StackPanel – Stacked 2013-03-08 13:17:25

回答

9

您需要將列表框放入網格中。 StackPanel的無限高度爲
,所以ScrollBar不會被啓用或可見。

<Grid> 
    <ListBox VerticalAlignment="Stretch" /> 
</Grid> 
+0

工作正常!謝謝Jehof – Stacked 2013-03-08 13:42:21