How to add an additional item to a ListBox WPF using ItemSource?

I have a WPF form with ListBox items bound to a method that receives items for a list. What I want is an extra item at the top of the ListBox, which behaves differently with the rest of the items.

For example, let's say I have a list of authors (binding to a list), and when I select an author, he fills out another list with books from that author. I would like to have an additional item in the lstAuthors list called "Show All" that will populate the other list with all the books. How to add this extra item to my list?

+6
c # wpf xaml
source share
1 answer

Use CompositeCollection to combine your collection with another collection containing your custom item. Then use a strongly typed data template for your special select all option, which does what you want in this section.

Other options include disabling scrolling in the list view, placing the list in the stack palette along with your selected everything, and then placing this stack panel in the scrollviewer or just placing the button in the user interface :)

+9
source share

All Articles