我正在尝试在单击按钮时创建XML节点。问题是,当我点击“保存”按钮时,它会覆盖值&不为每个项目生成节点。请告诉我最好的&轻松处理READ&在 WPF 中将文本框值写入XML。 请告诉我 WPF 的Form_Load的替代方法。
getChild(name)
}`
public class SaveXML
{
public static void SaveData(object obj, string filename)
{
XmlSerializer sr = new XmlSerializer(obj.GetType());
XmlSerializer rs = new XmlSerializer(obj.GetType());
TextWriter writer = new StreamWriter(filename);
sr.Serialize(writer, obj);
writer.Close();
}
}
public class Products
{
private string DatePick;
private string name;
private string category;
private string volume;
private string volunit;
private string quantity;
private string purprice;
private string sellprice;
public Products() { }
public Products(string DatePick, string name, string category, string volume, string volunit, string quantity, string purprice, string sellprice)
{
this.DatePick = DatePick;
this.name = name;
this.category = category;
this.volume = volume;
this.volunit = volunit;
this.quantity = quantity;
this.purprice = purprice;
this.sellprice = sellprice;
}
public string DatePicker
{
get {return DatePick;}
set {DatePick = value;}
}
public string Name
{
get {return name;}
set {name = value;}
}
public string Category
{
get {return category;}
set {category = value;}
}
public string Volume
{
get {return volume;}
set {volume = value;}
}
public string VolUnit
{
get {return volunit;}
set {volunit = value;}
}
public string Quantity
{
get {return quantity;}
set {quantity = value;}
}
public string PurPrice
{
get {return purprice;}
set {purprice = value;}
}
public string SellPrice
{
get {return sellprice;}
set { sellprice = value;}
}
}
答案 0 :(得分:0)
StreamWriter
构造函数有一个重载来指定追加模式。
TextWriter writer = new StreamWriter(filename, true);