开发者

How to automatically update UI when items are added to List<>

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


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


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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜