Is it possible to have empty rows displayed inside of a listbox/listview in wpf? I've been trying to replicate a repeating pattern of rows after my data so the listbox looks "full" but I haven't managed to figure out how to do this as of yet. The problem is the listbox will only show if there is any data in the observablecollection its bound to, so if there is no data the listbox wont render anything, and even if there is data, it'll only show the amount of rows the observablecollection is holding and nothing below the rows. I want to be able to have empty rows appearing in the listbox after the data, or a repeating pattern of empty rows if at all possible. Any help or tips would be appreciated.
1 Answer
There are several ways to achieve this result:
1) Add more (empty) rows to your collection
2) Use a separate collection that wraps your collection, and contains the empty rows (this is useful if you don't want to pollute your source with extra data)
3) Create a custom panel to use (instead of StackPanel, WrapPanel, etc) that your ItemsControl can use to display the items - then the panel itself handles displaying the empty rows. This a more robust and less hacky solution than 1 and 2, but requires more effort and WPF knowledge.
4) Create a subclass of ItemsControl (or ListBox/ListView) that automatically adds extra Items to fill the remaining space (similar to (3), but instead of a custom panel plugged into the ListBox, you are customizing the ListBox to create extra items for any panel to display. This is useful if you want to reuse the logic in different contexts where the consumer might want to vary the Panel type used.