【问题标题】:Binding ListBox inside a listBox WP8在 listBox WP8 中绑定 ListBox
【发布时间】:2015-03-13 12:33:19
【问题描述】:

我需要在ContryListBox中绑定一个名为cityListBox的列表框,类结构如下

public class Country
{
    public Country();

    public string ID { get; set; }

    public List<City> LstCity { get; set; }

    public string Title { get; set; }
}

我希望我的外部列表框应该带有 Country Title 作为标题,并在内部 listBox City 标题中,其中 city 也是一个具有 Id 和 Title 的类

我的 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>

【问题讨论】:

    标签: xaml windows-phone-8 binding listbox


    【解决方案1】:
    <!--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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-03
      • 2012-06-15
      • 2011-08-14
      相关资源
      最近更新 更多