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