0

I have a VirtualizingStackPanel with items from an ItemsSource. There are more items than space to display all the items in the VirtualizingStackPanel.

Example: I have space for 5.3 items but i have 7 items. Now i want the VirtualizingStackPanel to show 5 items and hide the rest.

Problem: The panel shows 6 items. The last item is overflowing.

Is it possible to show only 5 items (= no overflowing items) in this case, only with XAML?

The current code of my StackPanel:

<ItemsControl ItemTemplate="{StaticResource rpTemplate}" ItemsSource="...">
  <ItemsPanelTemplate>
    <VirtualizingStackPanel Orientation="Vertical" />
  </ItemsPanelTemplate>
</ItemsControl>

And my DataTemplate:

<DataTemplate x:Key="rpTemplate">
  <Label Content="{Binding Name}" HorizontalAlignment="Left" />
</DataTemplate>

It don't have to be VirtualizingStackPanel, it can be a StackPanel, DockPanel, whatever, as long as i can list the items.

fedab
  • 978
  • 11
  • 38
  • You could declare a custom `Panel` to do that for you, but creating custom virtualizing `Panel`s is not for the feint hearted. – Sheridan Aug 20 '14 at 09:46
  • @Sheridan I can use a custom `Panel` too (updated my question). Can you explain a little bit more what steps are required to archieve that kind of panel? – fedab Aug 20 '14 at 10:56
  • Unfortunately, that is off topic for this website as it is far too broad and too complex. There is a good chapter that covers it in the WPF Control Development Unleashed book, but unfortunately their previously available online version is no longer available. – Sheridan Aug 20 '14 at 11:13
  • I recall answering something very similar a while back. Does this question help you? [Virtualizing Panel that doesn't crop items](http://stackoverflow.com/q/9416047/302677) – Rachel Aug 20 '14 at 13:55
  • @Rachel: I currently working on my problem, your solution is helping me, thanks. I am working on a little bit different approach with an attached property. – fedab Aug 20 '14 at 15:24

1 Answers1

0

I found 3 solutions:

The first one (mentioned from Rachel in the comments) is using a converter.

The second one (i found this is the easiest): make a new class inherited from my Panel and use that

And i tried a third solution and found a solution with Blend behaviors

Community
  • 1
  • 1
fedab
  • 978
  • 11
  • 38