Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
307 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 Answer

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());

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...