简体   繁体   English

如何通过代码动态更新listviewitem

[英]How to dynamically update a listviewitem through code

I have a listview and would like to update the text of one of the columns for a specific listviewitem (row). 我有一个listview,并且想为特定的listviewitem(行)更新其中一列的文本。

How would I go about doing this? 我将如何去做呢?

Hard to say without any context because there are so many ways you could populate your list! 没有上下文就很难说,因为有很多方法可以填充列表!

The generic answer is you bind your list to a collection view which itself binds its source to your viewmodel (or you bind directly to your viewmodel if you don't need CollectionView features). 通用答案是将列表绑定到集合视图,该列表本身将其源绑定到视图模型(或者,如果不需要CollectionView功能,则直接绑定到视图模型)。

When you want to modify your list, you make sure you raise a modification notification on your property, and XAML binding will take care of updating everything. 当您想要修改列表时,请确保对属性引发修改通知 ,并且XAML绑定将负责更新所有内容。

It is really basic stuff on dependency property and binding, you should read more about this topic. 这确实是有关依赖项属性和绑定的基础知识,您应该阅读有关此主题的更多信息。 MVVM-light is a very light framework that allows you to take care of all kinds of binding-related issues with a very clean and neat flavor. MVVM-light是一个非常轻便的框架,它使您能够以非常干净利落的方式处理各种与绑定有关的问题。 You will also find some very good self-explanatory webcasts from the author of the website about all those topics. 您还将从该网站的作者那里找到有关所有这些主题的很好的自我解释性网络广播。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM