Trying to get a Windows Phone 8 ListPicker to work

扶醉桌前 提交于 2019-12-12 09:49:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!