private static void OnModalConfirmClicked(object sender, RoutedEventArgs e) { if (sender is Button button) { var window = VisualTreeHelpers.GetParent <Window>(button); if (window != null) { // Modal Windows can set DialogResult, Modeless will raise an exception, so we just close it in this case try { window.DialogResult = true; } catch { try { window.Close(); } catch { } } } } }
private static void OnCloseClicked(object sender, RoutedEventArgs e) { if (sender is Button button) { var window = VisualTreeHelpers.GetParent <Window>(button); if (window != null) { try { window.Close(); } catch { } } } }