using System.Windows; using System.Windows.Input; using WPFCustomMessageBox; namespace MPF.UI.Windows { public class WindowBase : Window { #region Event Handlers /// /// Handler for CloseButton Click event /// public void CloseButtonClick(object sender, RoutedEventArgs e) { try { DialogResult = false; } catch { } Close(); } /// /// Handler for MinimizeButton Click event /// public void MinimizeButtonClick(object sender, RoutedEventArgs e) { WindowState = WindowState.Minimized; } /// /// Handler for Title MouseDown event /// public void TitleMouseDown(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Left) DragMove(); } #endregion /// /// Display a user message using a CustomMessageBox /// /// Title to display to the user /// Message to display to the user /// Number of options to display /// true for inquiry, false otherwise /// true for positive, false for negative, null for neutral public bool? DisplayUserMessage(string title, string message, int optionCount, bool flag) { // Set the correct button style var button = optionCount switch { 1 => MessageBoxButton.OK, 2 => MessageBoxButton.YesNo, // This should not happen, but default to "OK" _ => MessageBoxButton.OK, }; // Set the correct icon MessageBoxImage image = flag ? MessageBoxImage.Question : MessageBoxImage.Exclamation; // Display and get the result MessageBoxResult result = CustomMessageBox.Show(this, message, title, button, image); return result switch { MessageBoxResult.OK or MessageBoxResult.Yes => true, MessageBoxResult.No => false, _ => null, }; } } }