简体   繁体   中英

Remove a specific item from a longlistselector in wp7

I have a items in longlistselector. So i was trying to delete a specific item from a longlistselector in wp7 c#?

您可以使用简单的方法removeAt(position)

you need to declare your itemsource for your longlistselector to be type ObservableCollection , so that when you modify your itemsource, your longlistselector would response to the change accordingly.

T could be your custom type, for example :

//Photo is my custom class
ObservableCollection<Photo> photos;

Example code :

//Declare itemsource    
ObservableCollection<string> list;

//Bind to longlistselector dynamically somewhere in code
longlistselector.ItemSource = list;

//Add items into your source
list.Add("test1");
list.Add("test2");
list.Add("test3");

//Delete items
list.RemoveAt(input item index here);

//OR

list.Remove(item); //if you're able to retrieve item ref;

And in your xaml :

//Notice the {Binding } syntax below for ItemSource property
<phone:LongListSelector ItemsSource="{Binding }" SelectionChanged="longListSelector_SelectionChanged"  Name="longListSelector" />

Hope it works well for you.

A code example for reference :

http://code.msdn.microsoft.com/wpapps/LongListSelector-Demo-45364cc9

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM