开发者

ObservableCollection of objects containing Lists

I am using an ObservableCollection for databinding as ItemsSource for DataGrid. Collection contains complex type objects. One of this type properties is a List of strings.

Just for now I see that when I update this List property from code nothing changes in the UI (the primary binding works fine). So, my question is: is开发者_运维知识库 it an expected behaviour? Maybe I should not use List as part of the type, but also use an ObservableCollection?

Update

Mode is set to OneWay.


Use a collection, instead of List, that implementes the interface INotifyCollectionChanged (like ObservableCollection). Then changes to the collection get populated to the ui.


Yes it is expected behaviour. The observable collection only notifies of changes to its own contents - that is add, delete, reorder.

What you are looking at is a change to an element in the observablecollection - if you want to see your changes to the class you put in, your element has to implement INotifyPropertyChanged.

So currently: If your list property on you complex object changes you won't see it, however if you change that too to be an observablecollection you could see changes to that collection in a sub-itemscontrol like a combobox - but not if you change the collection object to another one - so if you do not implement INotifyPropertyChanged you should set the collectionproperty before the binding is applied.


When you are updateding your list u have to call INotifyPropertyChange other wise UI wont get update the list result..

INotifyPropertyChange is the indication that here some changes occurred in the items source so update it.


This might help as well:

ObservableCollection that also monitors changes on the elements in collection

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜