private void Yes_Click(object sender, RoutedEventArgs e) { var tag = (sender as Button).Tag; long commentId = (long)tag; Comment comment = CommentDB.GetComment(commentId); foreach (Comment comm in ViewUserTask.comments) { if (comm.CommentId == commentId) { ViewUserTask.comments.Remove(comm); break; } } CommentDB.RemoveComment(commentId); RemovePopup.IsOpen = false; }