简体   繁体   English

从wp7中的longlistselector中删除特定项目

[英]Remove a specific item from a longlistselector in wp7

I have a items in longlistselector. 我在longlistselector中有一个项目。 So i was trying to delete a specific item from a longlistselector in wp7 c#? 所以我试图从wp7 c#中的longlistselector中删除特定项目?

您可以使用简单的方法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. 您需要将longlistselector的itemsource声明为ObservableCollection类型,以便在修改itemsource时,longlistselector会相应地响应更改。

T could be your custom type, for example : T可能是您的自定义类型,例如:

//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 : 在你的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 http://code.msdn.microsoft.com/wpapps/LongListSelector-Demo-45364cc9

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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