0
votes

In my WP7 app, I have this XAML for my ListPicker:

<toolkit:ListPicker HorizontalAlignment="Left" ExpansionMode="FullScreenOnly" Height="70" x:Name="ddLinks" VerticalAlignment="Top" Width="419" FullModeHeader="Category" SelectionChanged="ddLinks_SelectionChanged">
    <toolkit:ListPicker.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding linkCatName}" Name="lblLinkCat" />
            </StackPanel>
        </DataTemplate>
    </toolkit:ListPicker.ItemTemplate>
    <toolkit:ListPicker.FullModeItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding linkCatName}" Name="lblLinkCat" FontSize="48" />
            </StackPanel>
        </DataTemplate>
    </toolkit:ListPicker.FullModeItemTemplate>
</toolkit:ListPicker>

And this C# code behind:

while (condition)
{
     // code to set value of the vars
     this.ddLinks.Items.Add(new LinkCats(linkCatName, linkCatAnchor, linksInCat));
}

And a couple of objects:

public class LinkCats
{
    public string linkCatName { get; set; }
    public string linkCatAnchor { get; set; }
    public List<Links> linksInCat { get; set; }
    public LinkCats() { }

    public LinkCats(string pLinkCatName, string pLinkCatAnchor, List<Links> pLinksInCat)
    {
        this.linkCatName = pLinkCatName;
        this.linkCatAnchor = pLinkCatAnchor;
        this.linksInCat = pLinksInCat;
    }
}

public class Links
{
    public string linkName { get; set; }
    public string linkPath { get; set; }
    public Links() { }

    public Links(string pName, string pLink)
    {
        this.linkName = pName;
        this.linkPath = pLink;
    }
}

When the page is done loading, it shows the first item added as the selected item both in the control and when debugging. But if I click the ListPicker, nothing happens. I don't get to choose from the other options.

2
And why is that a problem that you get the first element as selected? The user could set the selected item after this or you could set it from code? Or am i missing something else, how many elements does your listpicker.Items contain ? :) - BigL
@BigL sorry forgot to add the issue I was facing. Edited and added the last sentence. - Ali Almohsen

2 Answers

0
votes

I think i know what is the problem but i'm not sure, so you have to test it first. The ListPickers ItemTemplate is only a single TextBlock and i think it should be put inside a Stackpanel.

Take a look at the link below.

Working With The WP7 ListPicker

0
votes

I think i know what is the problem but i'm not sure, so you have to test it first. The ListPickers ItemTemplate is only a single TextBlock and i think it should be put inside a Stackpanel.

Take a look at the link below.

Working With The WP7 ListPicker