Take the 2-minute tour ×

I have looked around a bit for this--can't find the proper collection

Here is the signature of my desired ViewModel. There are some interesting alternatives out there David Hill's CollectionViewModel or ObservableDictionary(Of TKey, TValue) on codeplex. But for now, I would like a built-in collection (for SL4) that handles this. Thanks

public class myViewModel: INotifyPropertyChanged
    public ObservableCollection<MyDataType> MyCollection;
    private ObservableCollection<MyDataType> _myCollection;

    public CurrentItem<MyDataType>() { return _myCollection.CurrentItem;} 

    public int GetCurrentIndex()  { return _myCollection.CurrentIndex;}
    public SetCurrentIndex(int Index)   { _myCollection.CurrentIndex = Index;}
share|improve this question

2 Answers 2

There isn't a built-in collection that provides this. However, you could just store the currentIndex value as a private int inside your ViewModel, and refer to it for the current index methods, as well as use it for CurrentItem<T>().

share|improve this answer
Well, like I say, programming is an exploration into my stupidity. I was looking for a method with a name like 'Item' or something. Now, in response to your answer I looked again and see that ObservableCollection has an indexer! var anItem = myCollection[7]; Thanks! –  Mark Bosley Jan 22 '11 at 4:35

But do we really need something like this? You can always bind to "ViewModel.MyCollection/" to get the currently selected item

share|improve this answer

Your Answer


