Reputation: 25282
I have a set of items in ItemsControl. I am displaying all of them but I want to make visible only a subset of items. So I kind of want to specify the visible area of ItemsControl (or any other element which supports this). Other elements could be seen after scrolling is applied.
I could do it on ViewModel-side and pass to ItemsControl only visible elements but I am interested in View-only solution. Is there any?
Upvotes: 1
Views: 79
Reputation: 3741
You can add a ScrollViewer
in your ItemsControl
's style, then if your items will overflow the width or height of the ItemsControl
a ScrollBar will appear.
<Style x:Key="ItemsControlStyle1" TargetType="{x:Type ItemsControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ItemsControl}">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Upvotes: 2