DataBinding and multiple Selected Items in ListBox

When working with a ListBox set to Multiple Selection Mode, it is often necessary to do something with the selected items.  An easy way to do this is shown in the code below.  In this quick example using type “Part”, we get the selected items from the list box, and remove them from the List.    By implementing an ObservableCollection<Part> and using databinding in our XAML, the Listbox will be updated automatically as items are deleted.  Be sure to include the using statement:  using System.Collections.ObjectModel


Set the ListBox DataBinding in your XAML to the name of the collection, in this case “MyParts”


Edit the Generated Item Container Template in Blend, and bind the “Content” property to “Name”


So now, when the app is run, the ListBox is populated, and when an item is selected, then deleted with a click of the button, the Listbox is updated automatically.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s