当我点击父节点(名称:Patience_name_1)时,我希望用子项获取该对象,并将其发送到其他页面(EditPatient)。
我不想为此目的使用查询字符串我想将它们作为类实例发送我该如何实现?
编辑:
这是.xaml和Patient类的cs文件:
public partial class PatientTree : Page
{
public PatientTree()
{
InitializeComponent();
fillTree(trvMenu);
}
public patients fillTree(TreeView treeView)
{
DataReader readXML = new DataReader();
patients patients = new patients();
patients.patients_list = readXML.ReadXML();
foreach (patient item in patients.patients_list)
{
TreeViewItem _patientNode = new TreeViewItem
{
Header = String.Format("Name:{0}", item.name),
IsExpanded = true
};
_patientNode.Items.Add(new TreeViewItem
{
Header = String.Format("Name:{0}", item.name),
IsExpanded = true,
});
_patientNode.Items.Add(new TreeViewItem
{
Header = String.Format("Surname:{0}", item.surname),
IsExpanded = true,
});
_patientNode.Items.Add(new TreeViewItem
{
Header = String.Format("Gender:{0}", item.gender),
IsExpanded = true,
});
foreach (exam exam in item.exam)
{
TreeViewItem _exam = new TreeViewItem
{
Header = "Exams",
IsExpanded = true
};
_exam.Items.Add(new TreeViewItem
{
Header = String.Format("Id:{0}", exam.id),
});
_exam.Items.Add(new TreeViewItem
{
Header = String.Format("Comment:{0}", exam.comment),
});
_exam.Items.Add(new TreeViewItem
{
Header = String.Format("Date:{0}", exam.DateString),
});
_patientNode.Items.Add(_exam);
}
treeView.Items.Add(_patientNode);
}
return patients;
}
private void trvMenu_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
var data = trvMenu.SelectedItem;
EditPatient patient = new EditPatient();
this.NavigationService.Navigate(patient);
}
}
患者类:
[Serializable, XmlRoot("patients")]
public class patients
{
[XmlElement("patient")]
public List<patient> patients_list { get; set; }
}
public class patient
{
[XmlElement("firstname")]
public string name { get; set; }
[XmlElement("lastname")]
public string surname { get; set; }
[XmlElement("age")]
public int age { get; set; }
public string gender { get; set; }
[XmlArray("exams"), XmlArrayItem("exam")]
public List<exam> exam { get; set; }
}
public class exam
{
[XmlElement("id", IsNullable = false)]
public int id { get; set; }
[XmlIgnore]
public DateTime date { get; set; }
[XmlElement("date")]
public string DateString
{
get
{
return XmlConvert.ToString(date, XmlDateTimeSerializationMode.Utc);
}
set
{
date = DateTime.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
}
}
[XmlElement("comment")]
public string comment { get; set; }
}