我在longlistselector中有一个项目。所以我试图从wp7 c#?
中的longlistselector中删除一个特定项目答案 0 :(得分:0)
您可以使用简单方法removeAt(position)
答案 1 :(得分: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