问题
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.
回答1:
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}" />
回答2:
I think your original code didn't work was because of a typo -
来源:https://stackoverflow.com/questions/15325243/trying-to-get-a-windows-phone-8-listpicker-to-work