그런 LongListSelector가 있습니다
<phone:LongListSelector Name="ListRecentFiles"
LayoutMode="Grid"
ItemsSource="{Binding}"
GridCellSize="140,140"
SelectionChanged="ListRecentFiles_SelectionChanged">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<Grid Background="Red" Margin="0,0,5,5">
<TextBlock Text="{Binding NoteTitle}" Style="{Binding PhoneTextNormalStyle}" />
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu x:Name="ContextMenu">
<toolkit:MenuItem x:Name="Delete" Header="Delete" Click="DeleteNote_Click" />
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
</Grid>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
이것은 DataContext입니다. public static ObservableCollection<Note> NoteItems;
그리고 LongListSelector에서 항목을 삭제하려고합니다.
private void DeleteNote_Click(object sender, RoutedEventArgs e)
{
Note selectedNote = (sender as MenuItem).DataContext as Note;
ListRecentFiles.ItemsSource.Remove(item);
NoteItems.Remove(selectedNote);
}
다른 XAML 페이지로 이동하여 돌아 오는 경우를 제외하고는 작동하지 않습니다.
이 페이지를 방문했지만 링크를 수정할 수 없습니다
더 많은 코드를 보지 않으면 무엇이 잘못되었는지 확인하기가 어렵습니다. 하지만 설정하는 경우
ListRecentFiles.DataContext = NoteItems;
그것은 정확하지 않습니다. 설정하려는
ListRecentFiles.ItemsSource = NoteItems;
XAML 선언 :
ItemSource="{Binding}"
그렇게 할 수 있습니다 (나머지 코드에 따라 다름). .ItemsSource가 올바르게 설정되면 다음 행이 표시됩니다.
NoteItems.Remove(selectedNote);
LongListSelector에서 시각적 항목을 제거하는 데 성공해야합니다. 어쨌든 다음 행을 수행해서는 안됩니다.
ListRecentFiles.ItemsSource.Remove(item);
목록이 너무 커져서 한 번에 모두 메모리에 맞지 않을 때 잘못된 일을합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다