C# wp8中的级联下拉列表

C# wp8中的级联下拉列表,c#,windows-phone-7,windows-phone-8,C#,Windows Phone 7,Windows Phone 8,我尝试创建级联下拉列表,当我选择第一个时,它工作正常。在选择更改时,我尝试绑定后面代码的第二个下拉列表,显示结果正常。但下拉列表显示为空。这是我的代码 Location ld = new Location(); ld = categoryList.SelectedItem as Location; string id = "0"; try { id = Convert

我尝试创建级联下拉列表,当我选择第一个时,它工作正常。在选择更改时,我尝试绑定后面代码的第二个下拉列表,显示结果正常。但下拉列表显示为空。这是我的代码

 Location ld = new Location();
            ld = categoryList.SelectedItem as Location;
            string id = "0";
            try
            {
                id = Convert.ToString(ld.id);
            }
            catch (Exception ex)
            { }
            if (id != "0")
            {
              //  lstSublocation.Visibility = Visibility.Visible;
                var lst = _lstlocation.Where(z => z.id == id).Select(z => z.sub_location).ToList();
                lstSublocation.ItemsSource = lst;
            }
在lst中显示2项

<toolkit:ListPicker x:Name="lstSublocation" Foreground="Black"   
                         BorderThickness="2" SelectionMode="Single"  
                        VerticalAlignment="Bottom" Margin="12,0,10,460" BorderBrush="LightGray"  Height="68" >
                    <toolkit:ListPicker.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding name}" Margin="12 0 0 0" Foreground="Black"/>
                            </StackPanel>
                        </DataTemplate>
                    </toolkit:ListPicker.ItemTemplate>
                    <toolkit:ListPicker.FullModeItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal" Margin="0 21 0 20">
                                <TextBlock Text="{Binding name}"
                                       Foreground="Black"
                                       />
                            </StackPanel>
                        </DataTemplate>
                    </toolkit:ListPicker.FullModeItemTemplate>
                </toolkit:ListPicker>

这是前端代码…:(2小时与此代码搏斗,如摔跤狂搏斗……)

代码应该可以工作(如发布的),这可能就是问题所在

var lst = _lstlocation.Where(z => z.id == id).Select(z => z.sub_location).ToList();
lstSublocation.ItemsSource = lst;
lstSublocation.ItemsSource=lst处放置断点并检查什么是
lst

确保它实际上是一个
列表
,并且
您的_模型
的属性为
名称
而不仅仅是一个公共变量。。像这样

public class sample_model
{
    public sample_model()
    {
        this.name = "default";
    }

    public string name { get; set; }   // this is bindable
    // public string name;             // this is NOT bindable
}

SelectedItem=“{Binding name}”
看起来很奇怪。这该怎么办?您已经绑定到项目模板中的名称。我将删除此项。尝试不同的方法获取数据:)@RichardRay是的,我们可以从列表中获取调试的屏幕截图吗?。它应该看起来像一棵树,而不仅仅是一个值列表。