Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
327 views
in Technique[技术] by (71.8m points)

c# - Accessing multiple selected items in a ListPicker

I came across the new Toolkit for Windows Phone that has the ListPicker control. Now after my searching I wanted to ask you people if I could actually select multiple items in a Listpicker and then use them?

I've completed the adding and selecting multiple items part by using SelectionMode="Multiple"

The XAML Code:

<toolkit:ListPicker x:Name="TopStoriesListPicker" Margin="0" Header="Top Stories" Width="422" SelectionMode="Multiple" FullModeHeader="Top Stories" TabNavigation="Local" Style="{StaticResource ListPickerStyle1}">
                        <sys:String>BBC</sys:String>
                        <sys:String>CNN</sys:String>
                        <sys:String>FOX</sys:String>
                        <sys:String>SKY</sys:String>
</toolkit:ListPicker>

Now how can I access these items after they have been multi checked? For one item I could have done:

if (TopStoriesListPicker.SelectedItem == CNN)
    do something

But now I have multiple items, plus the fact that these are no more proper items but have been defined by sys:String.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For getting all selected items use the SelectedItems property:

foreach (var item in listPicker1.SelectedItems)
    Debug.WriteLine(item.ToString());

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...