0
votes

I have a Listbox that I have bound to a list of strings.

I have set the Listbox's selection mode property to multiple so that several items within the listbox can be selected.

I want to bind the selected items to a property that would also be a list of strings.

However the Listboxes SelectedItems Property is readonly. Therefore I cannot bind to it. (I want the list box to remember my selection).

I don't see how microsoft intended the listbox to be used in this way..

If anyone can point me into the right direction, that would be much appreciated.

1
It is a bit of a workaround, but could you bind to the SelectedIndexes and try working from that.TheBlindSpring
Interesting thought. I am also thinking of wrapping the string in a row object which holds a 'isSelected' property and then style into the lisbox a setter which binds directly to the bindings is selected. Then the object would know itself whether it is selected or not. I will try this on Monday and then let everyone know how it goes...CreativeAbyss
You can create an attached property which will give you the selected items for binding.Ayyappan Subramanian

1 Answers

0
votes

I solved this issue by binding to a wrapper object that I created.

This wrapper contained the original property I wished to bind to an a boolean 'IsSelected' property.

I then styled the listbox to have a setter that specified the 'IsSelected' property to the 'IsSelected' property of the control.

This meant my object is now self aware of whether it is enabled and then the ViewMdoel can do whatever it needs to when the object changes this state.