I am using RIA services to serve entities to a MVVM-Light enabled Silverlight application.
I have a ViewModel which present a CollectionViewSource of entities to a listbox on the View. The reason I use a CollectionViewSource is so I can control the selected item in the ViewModel; when a new item is created I can create it and then select it for further editing (selecting an item in the listbox enables the editing of that item in a data form).
I need to enable dragdropping for the listbox to allow reordering of the items. I have looked at using the Silverlight Toolkit’s ListBoxDragDropTarget to enable this functionality but it doesn’t work – I assume this is because I need to set the listbox ItemsSource to an ObservableCollection.
If I change the CollectionViewSource in the ViewModel to an ObservableCollection how can I programmatically change the Selected Item of the listbox from the ViewModel?
Any ideas?
You can wrap your
ObservableCollection<T>within theCollectionViewSource…as seen here…so that it is the backing collection of data used by theCollectionViewSourcegaining theINotifyCollectionChangedbehavior without losing the benefits from theCollectionViewSource; which you need for selecting an item.An end to end example from Tim Heuer can be found here which should also help you out in achieving the complete solution.