滚动条,如果项目超过内部itemControl

问题描述:

ItemControl滚动条,如果项目超过内部itemControl

它显示一个内部ObservableCollection每个记录面板

我的问题是...。

当ObservableCollection增加窗口的大小不能容纳更多面板时,它只显示只有前六个面板。

因此,条件,ObservableCollection中每个记录的一个面板无法完成。

所以,我需要有滚动条,所以我可以访问每个面板。 它是如何实现的?

参见下面一个屏幕截图和Code它的下面

enter image description here

感谢......

您需要将您的面板托管在ScrollViewer之内。这允许它增长超出可用空间,而ScrollViewer增加了一个滚动条。

您可以通过modiyfing的ItemsControl模板做到这一点:

<ItemsControl> 
    <ItemsControl.Template> 
    <ControlTemplate> 
    <ScrollViewer> 
     <ItemsPresenter/> 
    </ScrollViewer> 
    </ControlTemplate> 
    </ItemsControl.Template> 
</ItemsControl> 
+0

谢谢你这么多它真的帮助我........ – Pritesh 2011-05-28 13:36:54

+0

大 - 你想给予好评/标记为答案? – ColinE 2011-05-28 13:37:14

+0

有没有什么办法可以对WrapPanel进行限制,比如它可以在一行中只显示10个项目....然后去换行.....谢谢........ – Pritesh 2011-05-28 13:40:01

把你想有滚动条到ScrollViewer任何控制。取自MSDN的示例:

<ScrollViewer HorizontalScrollBarVisibility="Auto"> 
    <StackPanel VerticalAlignment="Top" HorizontalAlignment="Left"> 
     <TextBlock TextWrapping="Wrap" Margin="0,0,0,20">Scrolling is enabled when it is necessary. 
     Resize the window, making it larger and smaller.</TextBlock> 
     <Rectangle Fill="Red" Width="500" Height="500"></Rectangle> 
    </StackPanel> 
    </ScrollViewer>