0

我在 longlistselector 中有一个项目。所以我试图从 wp7 c# 中的 longlistselector 中删除特定项目?

4

2 回答 2

0

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

于 2013-09-27T12:05:20.770 回答
0

您需要将 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

于 2013-11-09T15:46:22.757 回答