mardi 4 août 2020

C# Add items to Combobox as checkbox

Hello I am using XAML/WPF to create a Combobox and then using an XML to populate it

This is my XML

       <?xml version="1.0" encoding="utf-8" ?>
<ComboBox>
  <Customer name="John">
    <Data>
      <System>Linux</System>
    </Data>
  </Customer>
  <Customer name="Fernando">
    <Data>
      <System>Microsoft</System>
      <System>Mac</System>
    </Data>
  </Customer>
</ComboBox>

And this is the code that is used to populate the customer_comboBox

 XmlDocument doc = new XmlDocument();
 doc.Load(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) +@"\comboBox.xml");
 XmlNodeList customerList = doc.SelectNodes("ComboBox/Customer");

 foreach (XmlNode node in customerList)
 {
     customer_comboBox.Items.Add(node.Attributes["name"].InnerText);
 }

All this works but I would like to have the added items inside the Combobox be in the form of a checklist I done it through the XAML by adding Checkbox items manually but since I am populating the combobox automatically by reading the XML I like to do it through code. I assume I need to do some type of Data Binding but I do not know how and the answers I seen here are a few years old which reference DataSource which its not a Combobox attribute anymore




Aucun commentaire:

Enregistrer un commentaire