Wpf selecteditem not updating

To help me demonstrate, I’ve knocked up a toy View Model: it has on it an Available Names property that will be the data source for the List Box, a Selected Names property which is the reason we’re going through the whole exercise, and a Summary property which displays the number of selected items to prove that the data binding is working correctly.

wpf selecteditem not updating-27

For the Selected Item and Selected Value bindings, I do not set a mode – this is because “Mode=Two Way” is the default.

Two Way means that we want to update the property on the View Model when the selection changes, and if the property on the View Model changes we want to update the Selected Item/Selected Value on the Combo Box. I've been intrigued by computers since I was 12, staying in at recess to code QBASIC on the old Apple II. NET Access Denied Active MQ Active MQ-Camel Attribute Behavior C# Camel Cassandra Combo Box Connecting Cross-Field Data Binding Data Context Display Member Path Double Click Enumerate Event Example Framework Element GAC IData Error Info INotify Property Changed Instances Items Source Karaf Lucandra Lucandra.

Many moons ago, I asked on the WPF forums if anybody had a way of data-binding the Selected Items property of a List Box.

Standard data binding doesn’t work, because the Selected Items property is read-only, and understandably so: how would you like it if I injected an arbitrary collection into your List Box and expected you to keep it up to date as the selection changed?

In my solution, I define an attached property that you attach to a List Box (or Data Grid, or anything that inherits from Multi Selector) and allows you to specify a collection (via data binding, of course) that you want to be kept in sync with the Selected Items collection of the target.

Comments