I have a comboBox which get populated by an XML. It lists every item as checkbox item I would like the ComboBox to display the checked selections, like the image below
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>
This is my XAML
<ComboBox x:Name="customer_comboBox" HorizontalAlignment="Left" Margin="83,259,0,0" VerticalAlignment="Top" Width="172" SelectionChanged="customer_comboBox_SelectionChanged" >
<ComboBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</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");
List<string> customers = new List<string>();
foreach (XmlNode node in customerList)
{
customers.Add(node.InnerText);
}
customer_comboBox.ItemsSource = customers;
Aucun commentaire:
Enregistrer un commentaire