ComboBox Binding to XML in WPF

前端 未结 1 1798
猫巷女王i
猫巷女王i 2021-01-24 00:18

I know this question has been asked to death, but I have tried lots of the suggested answers I have found and the Combo Box is still not populating when I start the WPF in VS201

1条回答
  •  心在旅途
    2021-01-24 00:54

    As for me, simpliest way is XmlSerializer.

    public class Person
    {
        public string personName;
        public string personEmail;
        public string personReports;
    }
    
    public class People
    {
        [XmlElement("Person")]
        public List Persons;
    }
    

    Load data:

    var people = (People)new XmlSerializer(typeof(People)).Deserialize(stream);
    employeeNameBox.ItemsSource = people.Persons;
    

    ComboBox code:

    
    

    0 讨论(0)
提交回复
热议问题