ComboBox Binding to XML in WPF

前端 未结 1 1783
猫巷女王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<Person> Persons;
    }
    

    Load data:

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

    ComboBox code:

    <ComboBox x:Name="employeeNameBox" IsReadOnly="False" HorizontalAlignment="Left" IsEditable="True" DisplayMemberPath="personName">
    
    0 讨论(0)
提交回复
热议问题