【问题标题】:How can I add scrolling to an ItemsControl?如何将滚动添加到 ItemsControl?
【发布时间】:2010-08-03 15:27:05
【问题描述】:
我想在 3*4 页中显示 ItemsControl 中的项目
一个很酷的功能是我可以更改ItemsPanel 的ItemsControl:
例如:
<ItemsControl>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Column='3' Row ='4'/>
...
我怎样才能启用滚动?如果面板是StackPanel,则启用滚动/分页。
但不适用于UniformGrid
【问题讨论】:
标签:
wpf
layout
scroll
itemscontrol
【解决方案1】:
目前尚不清楚您是要分页还是滚动,但我认为您的意思是后者。既然如此,只需将ItemsControl 放在ScrollViewer 中:
<ScrollViewer>
<ItemsControl ...>
</ItemsControl>
</ScrollViewer>
【解决方案2】:
可以改用模板并将 ScrollViewer 放在 ItemsControl 中并将其用于呈现的内容 - 这样内容包含在滚动条中而不是整个 ItemsControl 中。
<ItemsControl>
<ItemsControl.Template>
<ControlTemplate>
<ScrollViewer>
<ItemsPresenter />
</ScrollViewer>
</ControlTemplate>
</ItemsControl.Template>
</ItemsControl>