[英]Remove a specific item from a longlistselector in wp7
我在longlistselector中有一个项目。 所以我试图从wp7 c#中的longlistselector中删除特定项目?
您可以使用简单的方法removeAt(position)
您需要将longlistselector的itemsource声明为ObservableCollection类型,以便在修改itemsource时,longlistselector会相应地响应更改。
T可能是您的自定义类型,例如:
//Photo is my custom class
ObservableCollection<Photo> photos;
示例代码:
//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;
在你的xaml中:
//Notice the {Binding } syntax below for ItemSource property
<phone:LongListSelector ItemsSource="{Binding }" SelectionChanged="longListSelector_SelectionChanged" Name="longListSelector" />
希望它对您有用。
一个代码示例供参考:
http://code.msdn.microsoft.com/wpapps/LongListSelector-Demo-45364cc9
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.