Updating ListBox.SelectedItem

Nov 9, 2010 at 10:32 PM

Hi Everyone,

I have a ListBox that I let CM bind to so that it displays the views for the view models that are contained in a "ViewModels" property on a main VM with a matching name.  I also let the conventions handle binding to the corresponding SelectedViewModel property.  When I select an item in the list, CM successfully sets the SelectedViewModel property.  However, the problem I'm having is that when I set the SelectedViewModel property in code the selection shown in the UI is not being updated.  Any ideas on how to make this happen?  



PS - I've tried calling NotifyOfPropertyChang(() => SelectedViewModel); after setting the property.

Nov 10, 2010 at 2:49 AM

Can you confirm that your property has both a getter and a setter and that the setter raises the change notification?

Nov 11, 2010 at 3:58 PM

Hi Rob,

At first I was using an auto property so I had to call NotifyOfPropertyChange outside of the setter, but I moved it into the setter and it didn't make a difference.  I also tried making it a dependency property and that didn't work either.  The scenario I'm dealing with is that I have tasks in a list box and I need to reorder them.  I've got that working, but I want to keep the last selected item in the list highlighted so the user knows they can continue clicking the move task button repeatedly in order to further advance the item in the list.  We've made some customizations to the framework, so I may have introduced a bug somewhere.  Do you need me to try to reproduce the problem in a sample project?



Nov 11, 2010 at 4:07 PM

If you could create a repro that would really help...what your trying is something I do regularly..so I'm not really sure what it could be without seeing some code. You can email it to robertheisenberg at hotmail dot com