Do not show partial items in a WPF listbox

Posted by David Martin on Stack Overflow See other posts from Stack Overflow or by David Martin
Published on 2010-03-30T15:48:54Z Indexed on 2010/03/30 16:03 UTC
Read the original article Hit count: 334

Filed under:

I've tried Google and I've tried Bing to no avail. Does anyone here have an idea on how to prevent partial items from appearing in a listbox in WPF? In case that does not make sense here is an example: Listbox is 200 pixels tall - each item is 35 pixels tall. That means I can show 5.7 items. 7/10 of an item is undesirable. I'd like to limit it to showing only 5 items. The user could then scroll to see the additional items.

Should I A) try to dynamically size the listbox or ScrollViewer ViewPort so that it fits perfectly? Or B) implement a custom panel that would not arrange a child whose desired height is more than the remaining vertical space?

Any thoughts would be greatly appreciated. Last note: If anyone knows of a 3rd party control (listbox or grid) that does this I would be interested in that as well.

© Stack Overflow or respective owner

Related posts about wpf