tags:

views:

26

answers:

1

I need a control that implements the usual functionality an ItemsControl, with the following behavior:

If number of items to display does not fit into available space, instead of showing the scrollbar, the number of displayed items is reduced to be able to fit, while leaving available space for a "More..." or "< >" elements. When number of items is small enough, then "More..." section becomes invisible. So if you dynamically resize the control, the "More..." section would appear or disappear, depending on the size.

I do not need a complete solution, just a direction, but I would prefer something that is "in WPF spirit", utilizing the layout engine as much as possible. Also, if you happen to know about an existing solution, it would be great as well.

A: 

In WPF and Silverlight, an ItemsControl can use a VirtualizingPanel subclass which creates the UIElements on-demand. If you implement your own subclass (instead of using VirtualizingStackPanel, for example) which implements the IScrollInfo interface, then what you can do is in the MeasureOverride() method, you could populate the viewable area with as many items as can fit (minus 1) and place a "More..." element at the end.

There's a couple of good blog postings about implementing your own VirtualizingPanel and IScrollInfo around, but to start you off, Dan Crevier has a series on implementing a VirtualizingTilePanel:

http://blogs.msdn.com/dancre/archive/tags/VirtualizingTilePanel/default.aspx

In his 4th post (the last one he did), he's got a link to download the source code which you might find useful.

Then there's Ben Constable's blog series on IScrollInfo at http://blogs.msdn.com/bencon/archive/tags/Avalon+2F00+WPF/default.aspx

I've been using these 2 resources myself this past week to help me implement the VirtualizingPanel and VirtualizingStackPanel classes in Moonlight (which is another resource you are free to look over if you're not afraid to use Subversion to grab svn://anonsvn.mono-project.com/source/trunk/moon. You'll find my implementation of VirtualizingStackPanel under moon/class/System.Windows/System.Windows.Controls/VirtualizingStackPanel.cs

Hope that helps.

jstedfast