C# 从wp7中的longlistselector中删除特定项

C# 从wp7中的longlistselector中删除特定项,c#,windows-phone-7,windows-phone-8,C#,Windows Phone 7,Windows Phone 8,我在longlistselector中有一个项目。因此,我试图从wp7 c#?中的longlistselector中删除一个特定项。您可以使用简单的方法removeAt(position)您需要将longlistselector的itemsource声明为类型ObservableCollection,以便在修改itemsource时,longlistselector将相应地响应更改 T可以是您的自定义类型,例如: //Photo is my custom class ObservableColl

我在longlistselector中有一个项目。因此,我试图从wp7 c#?

中的longlistselector中删除一个特定项。您可以使用简单的方法removeAt(position)

您需要将longlistselector的itemsource声明为类型ObservableCollection,以便在修改itemsource时,longlistselector将相应地响应更改

T可以是您的自定义类型,例如:

//Photo is my custom class
ObservableCollection<Photo> photos;
//Photo是我的自定义类
可观察收集照片;
示例代码:

//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;
//声明itemsource
可观察收集清单;
//在代码中的某个位置动态绑定到longlistselector
longlistselector.ItemSource=列表;
//将项目添加到源中
列表。添加(“测试1”);
列表。添加(“测试2”);
列表。添加(“测试3”);
//删除项目
list.RemoveAt(在此处输入项目索引);
//或
列表。删除(项目)//如果您能够检索项目ref;
在您的xaml中:

//Notice the {Binding } syntax below for ItemSource property
<phone:LongListSelector ItemsSource="{Binding }" SelectionChanged="longListSelector_SelectionChanged"  Name="longListSelector" />
//注意下面ItemSource属性的{Binding}语法
希望它对你有用

参考代码示例:


共享您为其创建的项目。如果不提供源代码,我们无法回答您的问题。如果实现了序列化,则无法删除(对象)