Question

I have just started trying to build my first wp7 app, and I am learning c# and xaml from scratch. I have made good progress but I am having trouble with the silverlight toolkit listpicker.

I databound a list picker using the following template

        </DataTemplate>
        <DataTemplate x:Name="pitVolume">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Litres}"  Margin="12 0 0 0"/>
            </StackPanel>
        </DataTemplate>

bound to this: List concunitsource = new List();

            concunitsource.Add(new Units() { Molar = "pM", Factor = -12});
            concunitsource.Add(new Units() { Molar = "nM", Factor = -9, Grams = "ng"});
            concunitsource.Add(new Units() { Molar = "µM", Factor = -6, Grams = "µg", Litres = "µL" });
            concunitsource.Add(new Units() { Molar = "mM", Factor = -3, Grams = "mg", Litres = "mL" });
            concunitsource.Add(new Units() { Molar = "M", Factor = 0, Grams = "g", Litres = "L" });

The listpicker binds but I get two small blank but selectable entries at the top (presumably space for pico and nano litres). I left these out as they would not get used by the user. Is there anyway to prevent this, and just show the 3 that I want?

Was it helpful?

Solution

I can think of a few ways but there are probably more:

The simplest would be to not load items in the ListPicker that won't be displayed. Or use Linq-to-Objects to filter out the items you want displayed to the collection that is bound to the control.

dspConcunitsource = concunitsource.Where(u => u.Litres != null).ToList();

You might look at using a CollectionViewSource to filter out items in the collection you don't want displayed based on some criteria.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top