private async void DeleteNote(object sender, RoutedEventArgs e) { if (!(sender is Button button)) { return; } await _controller.DeleteNote(button.Tag.ToString()); var parent = VisualTreeHelper.GetParent(button); while (!(parent is Window)) { parent = VisualTreeHelper.GetParent(parent); } (parent as Window).Close(); ShowNoteList(); }