我需要在ContryListBox中绑定一个名为cityListBox的列表框,其中包含以下类的结构
public class Country
{
public Country();
public string ID { get; set; }
public List<City> LstCity { get; set; }
public string Title { get; set; }
}
我希望我的外部列表框应该带有国家标题作为标题和inner listBox City标题,其中city也是一个具有Id和标题的类
我的xaml代码:
<ListBox x:Name="ContryListBox">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<Bewise:ExpanderControl HeaderText="{Binding Title, Mode=OneWay}" >
<Bewise:ExpanderControl.ContentArea>
<ListBox x:Name="cityListBox " >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<CheckBox></CheckBox>
<TextBlock Text="{Binding Title}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Bewise:ExpanderControl.ContentArea>
</Bewise:ExpanderControl>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
答案 0 :(得分:2)
<!--Added ItemsSource binding-->
<ListBox x:Name="ContryListBox" ItemsSource="{Binding YourCountryListProperty}>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<Bewise:ExpanderControl HeaderText="{Binding Title, Mode=OneWay}" >
<Bewise:ExpanderControl.ContentArea>
<!--Added ItemsSource Binding-->
<ListBox x:Name="cityListBox" ItemsSource="{Binding LstCity}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<CheckBox></CheckBox>
<TextBlock Text="{Binding Title}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Bewise:ExpanderControl.ContentArea>
</Bewise:ExpanderControl>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>