I have this LongListSelector in a page:
<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>
And this is the EditVideo
private void EditVideo(object sender, RoutedEventArgs e)
{
VideoItem selectedVideo = (sender as MenuItem).DataContext as VideoItem;
if (video == null) { return; }
//Do Stuff
this.RelodeTableData();
}
And the 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);
}
});
}
And the problem is that when the user edit a item and try to edit another item after that he get the last item he edit in selectedVideo.
I use the ReloadTableData to refresh the list data after i edit it.
Ok after a lot of searching how to fix this thing. i fount that if i add Unload method to the ContextMenu and this is clear the DataContext.
private void ContextMenu_Unload(object sender, RoutedEventArgs e)
{
ContextMenu conmen = (sender as ContextMenu);
conmen.ClearValue(FrameworkElement.DataContextProperty);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With