views:

41

answers:

2

Wihtin my current project I have to add data items to a List<> object. I am using a list due to the fact that it is being derived from an external type and due to how it is being utilized by other applications I do not have the ability to request that the type be changed in the assembly from List to ObservableCollection. So as of right now I am stuck using List<> for my storage collection. Since List<> does not automatically update the UI when items are add I was wondering how to go about invoking this update? thanks in advance

+4  A: 

Create an ObservableCollection<T> out of the List and bind it to the UI element.

Veer
Beat me to it, this is the approach that I use whenever I need to subscribe to list events on my UI etc.
Brian Scott
A: 

If you are using a ViewModel and implementing INotifyPropertyChanged, it is as easy as throwing the PropertyChanged event with the name of the List<> property as the propertyName argument.

PropertyChangedEventHandler handler = this.PropertyChanged;

if (handler != null)
{
       var e = new PropertyChangedEventArgs(propertyName);
       handler(this, e);
}
Andy.Streeval
Thanks Andy this is a great point. With this project I am still working in model view presenter patterns and I am working on getting to the MVVM pattern. This is a great tip and point to reference moving forward.Thank yoU!
randyc