C# WPF MVVM Binding not updating

China☆狼群 提交于 2019-12-02 12:35:52

You're binding to the TestModels collection, so the converter is only going to be invoked when that property changes. Your loop changes the elements within the collection but it doesn't change the value of TestModels itself. If you want this to work then you basically have two options:

1) Use an attached behaviour and make it subscribe to the INotifyCollectionChanged CollectionChanged property when the TestModels binding is first made. It will then need some way of providing the result back to the Label, that can be achieved with a separate attached property.

2) Do all this in your view model, which is really where it should be being done anyway. Any time you find yourself doing anything but the most basic, application-independent tasks in your converters it's usually a sign that your view model layer isn't doing its job properly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!