2011-05-28 33 views
3

ItemControl滾動條,如果項目超過內部itemControl

它顯示一個內部ObservableCollection每個記錄面板

我的問題是...。

當ObservableCollection增加窗口的大小不能容納更多面板時,它只顯示只有前六個面板。

因此,條件,ObservableCollection中每個記錄的一個面板無法完成。

所以,我需要有滾動條,所以我可以訪問每個面板。 它是如何實現的?

參見下面一個屏幕截圖和Code它的下面

enter image description here

感謝......

回答

6

您需要將您的面板託管在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

0

把你想有滾動條到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> 
相關問題