简体   繁体   中英

cascading dropdown in wp8

I'm try to create cascading dropdown when i select first one it's working fine.On SelectionChanged i'm try to bind second drop down on code behind it's show the result fine.But Dropdown show empty.here is my code..

 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;
            }

In lst show 2 items.

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

Here is front end code ..... :( 2 hours struggle with this code like wrestlemania fight... :)

Code should work (as posted), this is probably where the problem is

var lst = _lstlocation.Where(z => z.id == id).Select(z => z.sub_location).ToList();
lstSublocation.ItemsSource = lst;

Put a break point at lstSublocation.ItemsSource = lst; and check what lst is

Make sure it's actually a List<your_model> and that your_model has a Property of name not just a public variable.. like this

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM