我LongListSelector
在一个页面中有这个:
<Controls:LongListSelector Height="Auto" x:Name="historylist" HorizontalContentAlignment="Stretch"
Background="Black" SelectionChanged="DidPressSelectItem">
<Controls:LongListSelector.ItemTemplate>
<DataTemplate>
<local:SearchTemplateSelector Content="{Binding}" HorizontalContentAlignment="Stretch">
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu Opened="ContextMenu_Opened">
<toolkit:MenuItem Header="Edit" Click="EditVideo"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
.
.
.
.
</local:SearchTemplateSelector>
</DataTemplate>
</Controls:LongListSelector.ItemTemplate>
这是EditVideo
private void EditVideo(object sender, RoutedEventArgs e)
{
VideoItem selectedVideo = (sender as MenuItem).DataContext as VideoItem;
if (video == null) { return; }
//Do Stuff
this.RelodeTableData();
}
和RelodeTableData
:
private void RelodeTableData()
{
System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
{
searchResults.Clear();
for (int i = 0; i < historyRep.historyArray.Count; i++)
{
VideoItem item = historyRep.historyArray[i];
searchResults.Add(item);
}
});
}
问题是,当用户编辑一个项目并尝试编辑另一个项目之后,他得到了他编辑的最后一个项目selectedVideo
。
编辑后,我使用 ReloadTableData 刷新列表数据。