简体   繁体   English

将逗号分隔的列表框项目转换为 XML 文件

[英]convert comma delimited listbox items to XML file

I need code that adds employee data from text box to List item with comma delimited for Display purpose.我需要将员工数据从文本框中添加到列表项的代码,以逗号分隔用于显示目的。 Now when submit button gets pressed it takes list of employee from listbox and write it out in XML format.现在,当提交按钮被按下时,它会从列表框中获取员工列表并以 XML 格式写出。 Can anyone help me out with it.任何人都可以帮我解决这个问题。

在此处输入图片说明

I would recommend using MVVM approach to implement this.我建议使用 MVVM 方法来实现这一点。 Have the details (name, age etc) fields bind to string properties in the ViewModel, then make Add Employee button use Command binding.将详细信息(姓名、年龄等)字段绑定到 ViewModel 中的字符串属性,然后让添加员工按钮使用Command绑定。 The command should add the employee into an ObservableCollection<Employee> , whereas you would need to have an Employee model class.该命令应该将员工添加到ObservableCollection<Employee> ,而您需要有一个Employee模型类。 If you still insist on having comma-separated strings to display those employees, then you can let the listbox do a MultiBinding to the ObservableCollection<Employee> , and set a IMultiValueConverter .如果您仍然坚持使用逗号分隔的字符串来显示这些员工,那么您可以让列表框对ObservableCollection<Employee>进行MultiBinding ,并设置一个IMultiValueConverter

For serialization to XML, you can simply make the Employee class implement ISerializable , and serialize that collection of employees back to XML using System.Xml.Serialization.XmlSerializer class.对于 XML 序列化,您可以简单地使Employee类实现ISerializable ,并使用System.Xml.Serialization.XmlSerializer类将该Employee集合序列化回 XML。

It is hard to explain everything here, if you are interested in using MVVM, you should google for it and start reading on it.在这里很难解释所有内容,如果您对使用 MVVM 感兴趣,您应该 google 并开始阅读它。

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

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