如何使用C#更新wpf中的列表视图 [英] How to update the List View in wpf using C#

查看:244
本文介绍了如何使用C#更新wpf中的列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在开发一个WPF应用程序,其中我有一个带有列表视图的主要wpf表单和一个打开Popup的按钮,该实习生有两个带有Add按钮的文本字段。单击添加按钮后,两个txts将添加到本地系统上的xml文件中,之后将关闭弹出窗口。现在我的要求是,一旦弹出窗口关闭,它的父主窗体ListView应该使用已写入xml文件的txt名称进行更新。



每当我'单击添加按钮,txt名称已添加到xml文件中,弹出窗口将自动关闭。但是当控件返回到主窗体时,listView不会自动更新。请有人帮我这个。



提前致谢。



Bhaskar D.

Hi,
I'm developing a WPF app, in which i have a main wpf form with List View and a button to open a Popup which intern having two text fields with Add button. Once I click the Add button, thew two txts will be added to a xml file on my local system and the popup will be closed after that. Now my requirement is that once the popup is closed, its parent main form ListView should be updated with the txt names which have been written to xml file.

Whenever I'm clicking the Add button the txt names have been added to the xml file and popup is closed automatically. But when the control goes back to the main form, the listView is not updates automatically. Please anyone help me on this.

Thanks in advance.

Bhaskar D.

推荐答案

使用ObservableCollection而不是通用列表并实现INotifyPropertyChange。

请阅读以下链接以获取更多信息。

https://social.msdn.microsoft.com/forums/silverlight/en-US/b993e9a1-4b06-4018-ab14 -cbe254e3c0a6 / difference-between-list-and-observablecollection
Use ObservableCollection instead of generic list and implement INotifyPropertyChange.
Read below link for more information.
https://social.msdn.microsoft.com/forums/silverlight/en-US/b993e9a1-4b06-4018-ab14-cbe254e3c0a6/difference-between-list-and-observablecollection


我想你也可以手动刷新你的项目:listView.Items.Refresh()
i think you could also manually refresh your items with: listView.Items.Refresh()


这篇关于如何使用C#更新wpf中的列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆