I have a ComboBox with CheckBox as its ItemTemplate. The ComboBox's ItemsSource is bound to my XML document:
XML:
<?xml version="1.0" standalone="yes"?>
<Table>
<Stores>
<Store storename="CandyLand">
<Candy id="Stars"/>
<Candy id="Chewy"/>
</Store>
<Store storename="FunYums">
<Candy id="Stars"/>
<Candy id="Sour"/>
<Candy id="Chewy"/>
</Store>
</Stores>
<PossibleCandy>
<Candy id="Stars"/>
<Candy id="Mint"/>
<Candy id="Sour"/>
<Candy id="Chewy"/>
</PossibleCandy>
</Table>
XAML:
</Page.Resources>
<XmlDataProvider x:Key="CandyData" XPath="Table"/>
</Page.Resources>
<ListView Name="lstStores" DataContext="{StaticResource CandyData}" ItemsSource="{Binding XPath=Stores/Store}" DisplayMemberPath="@storename"/>
<ComboBox Name="cbCandy" DataContext="{StaticResource CandyData}" ItemsSource="{Binding XPath=PossibleCandy/Candy}" Width="180" IsEditable="True" IsReadOnly="True">
<ComboBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding XPath=@id}" IsChecked="{Binding IsChecked, Mode=TwoWay}" Checked="Candy_Check" Unchecked="Candy_Uncheck" Padding="1" Width="200"/>
<!--<CheckBox Content="{Binding XPath=@id}" IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ComboBoxItem}}, Path=IsSelected}" Checked="Candy_Check" Unchecked="Candy_Uncheck" Padding="1" Width="200"/>-->
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
When the user selects one of the Stores in lstStores, I want the ComboBox's CheckBoxes to be selected based on the Candy in the selected store (i.e. if the user selects FunYums from lstCandy, Stars,Sour, and Chewy are checked in cbCandy.) I've tried the 2 different CheckBoxes as you can see.
I'm also flexible with how I organize my XML, if that helps.
Thanks!
Aucun commentaire:
Enregistrer un commentaire