开发者

Item replacement in ObservableCollection doesn't update WPF ItemsControl

I have (I thought) a fairly conventional WPF app.

I've

<ListBox ItemsSource="{Binding MyList}" ...

MyList is an

ObservableCollection<MyItem>

MyItem does not implement INotifiyPropertyChanged

when I Add items to the OC, the UI updates with out issue. When I replace item开发者_运维百科s, via

MyList[index] = newItem;

the UI only updates occasionally. Sometimes selecting another control on the window helps, but often not.Updates are arriving at about 5 per second. If it matters, this is WPF 4 on a Win7 x64 machine.


My guess it that you better use Remove() and Insert(index, item) instead of assigning to an indexed item. Removing and inserting items must raise the CollectionChanged delegate.


This makes absolutely no sense to me, replacements are registered by ObservableCollections and i had no problems with it so far...

I suspect the error lies somwhere else.

e.g. accidentally replacing the item with itself, destroying the binding to the data, things like that...

On a sidenote, if you ever encounter behaviour that occurs sometimes the error is quite likely to be in your own code logic because sometimes points toward indeterministic behaviour which you normally should not encounter in any decent framework.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜