dudledok
dudledok

Reputation: 2880

Trying to get a Windows Phone 8 ListPicker to work

The ListPicker functions, in that I can click on it and a full screen popup appears, but there are options to choose from.

My xaml:

                <toolkit:ListPicker ExpansionMode="FullScreenOnly" FullModeHeader="Select Module" Name="modulePicker">
                    <toolkit:ListPicker.ItemTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <TextBlock Text="{Binding moduleNumber}"/>
                            </StackPanel>
                        </DataTemplate>
                    </toolkit:ListPicker.ItemTemplate>
                    <toolkit:ListPicker.FullModeItemTemplate>
                        <DataTemplate>
                            <StackPanel">
                                <TextBlock Text="{Binding moduleNumber}"/>
                            </StackPanel>
                        </DataTemplate>
                    </toolkit:ListPicker.FullModeItemTemplate>
                </toolkit:ListPicker>

And the C# behind it includes:

String[] moduleNumber = { "AA1", "AA2", "AA3" };

and

    public MainPage()
    {
        InitializeComponent();
        this.modulePicker.ItemsSource = moduleNumber;
    }

So what do I need to do to get the strings listed in moduleNumber to display on the ListPicker?

If you need to know more just ask.

Upvotes: 3

Views: 9557

Answers (2)

sajiv
sajiv

Reputation: 1

I think your original code didn't work was because of a typo -

Upvotes: -2

Rob.Kachmar
Rob.Kachmar

Reputation: 2188

The code behind is fine. This is a xaml issue. Try this approach instead in your xaml file.

1) Define your data templates as PhoneApplicationPage Resources which bind to the moduleNumber array from the code behind.

2) Then bind your list picker to the templates.

<phone:PhoneApplicationPage.Resources>
    <DataTemplate x:Name="modulePickerItemTemplate">
        <StackPanel>
            <TextBlock Text="{Binding moduleNumber}"/>
        </StackPanel>
    </DataTemplate>
    <DataTemplate x:Name="modulePickerFullItemTemplate">
        <StackPanel>
            <TextBlock Text="{Binding moduleNumber}"/>
        </StackPanel>
    </DataTemplate>
</phone:PhoneApplicationPage.Resources>


<toolkit:ListPicker ExpansionMode="FullScreenOnly" FullModeHeader="Select Module" 
                    Name="modulePicker"
                    FullModeItemTemplate="{Binding modulePickerFullItemTemplate}" 
                    ItemTemplate="{Binding modulePickerItemTemplate}" />

Upvotes: 3

Related Questions