/// <summary> /// Add default "OK" button. /// </summary> private void _AddOkButton() { if (_buttons.Count == 0) { // if button not set - add OK button _okButton = new MessageBoxExButton(); _okButton.Caption = (string)App.Current.FindResource("ButtonHeaderOk"); _okButton.Value = MessageBoxExButtonType.Ok; _buttons.Add(_okButton); } }
/// <summary> /// Creates a button control based on info from MessageBoxExButton. /// </summary> /// <param name="button">Message box extended button.</param> /// <returns>GUI control.</returns> private SysControls.Button _CreateButton(MessageBoxExButton button) { SysControls.Button buttonCtrl = new SysControls.Button(); // init button buttonCtrl.Content = button.Caption; if (!string.IsNullOrEmpty(button.HelpText) && (0 < button.HelpText.Trim().Length)) { buttonCtrl.ToolTip = button.HelpText; } buttonCtrl.Click += new RoutedEventHandler(_Button_Click); buttonCtrl.Tag = (MessageBoxExButtonType?)button.Value; // Apply style to button buttonCtrl.Width = (double)App.Current.FindResource("DefaultPageButtonWidth"); buttonCtrl.Height = (double)App.Current.FindResource("DefaultPageButtonHeight"); buttonCtrl.Margin = new Thickness(10); return(buttonCtrl); }
/// <summary> /// Add a standard button to the message box. /// </summary> /// <param name="button">The standard button to add.</param> /// <param name="isCancelResult">The return value for this button in case if dialog /// closes without pressing any button.</param> private void _AddButton(MessageBoxExButtonType buttonType, bool isCancelResult) { // The text of the button. string caption = _GetButtonCaption(buttonType); // Text must be not null. Debug.Assert(!string.IsNullOrEmpty(caption)); // Create button. MessageBoxExButton button = new MessageBoxExButton(); button.Caption = caption; // The return value in case this button is clicked. button.Value = buttonType; if (isCancelResult) { button.IsCancelButton = true; } // Add a custom button to the message box. _msgBox.Buttons.Add(button); }
/// <summary> /// Find Ok button in buttons array and store. /// </summary> private void _StoreOkButton() { foreach (MessageBoxExButton button in _buttons) { if (MessageBoxExButtonType.Ok == button.Value || MessageBoxExButtonType.Yes == button.Value) { if (null == _okButton) { _okButton = button; } else { Debug.Assert(false); // NOTE: only one ok button supported. } } } }
/// <summary> /// Disable close button. /// </summary> private void _DisableCloseButton() { if (1 == _buttons.Count) _cancelButton = _buttons[0] as MessageBoxExButton; else if (1 < _buttons.Count) { if (_cancelButton == null) { // see if standard cancel button is present foreach (MessageBoxExButton button in _buttons) { if (button.IsCancelButton || MessageBoxExButtonType.Cancel == button.Value) { if (null == _cancelButton) _cancelButton = button; else { Debug.Assert(false); // NOTE: only one cancel button supported } } } if (null == _cancelButton) { // standard cancel button is not present, Disable close button _DisableCloseButton(this); } } } // else Do nothing }
private void _Dialog_KeyDown(object sender, System.Windows.Input.KeyEventArgs e) { if (e.Key == Key.Escape || e.Key == Key.Enter) { if (e.Key == Key.Escape) { _pressedButton = _cancelButton; } else // e.Key == Key.Enter { _pressedButton = _okButton; } DialogResult = (null != _pressedButton); Close(); e.Handled = true; } }
/// <summary> /// Creates a button control based on info from MessageBoxExButton. /// </summary> /// <param name="button">Message box extended button.</param> /// <returns>GUI control.</returns> private SysControls.Button _CreateButton(MessageBoxExButton button) { SysControls.Button buttonCtrl = new SysControls.Button(); // init button buttonCtrl.Content = button.Caption; if (!string.IsNullOrEmpty(button.HelpText) && (0 < button.HelpText.Trim().Length)) buttonCtrl.ToolTip = button.HelpText; buttonCtrl.Click += new RoutedEventHandler(_Button_Click); buttonCtrl.Tag = (MessageBoxExButtonType?)button.Value; // Apply style to button buttonCtrl.Width = (double)App.Current.FindResource("DefaultPageButtonWidth"); buttonCtrl.Height = (double)App.Current.FindResource("DefaultPageButtonHeight"); buttonCtrl.Margin = new Thickness(10); return buttonCtrl; }
/// <summary> /// Add a standard button to the message box. /// </summary> /// <param name="button">The standard button to add.</param> /// <param name="isCancelResult">The return value for this button in case if dialog /// closes without pressing any button.</param> private void _AddButton(MessageBoxExButtonType buttonType, bool isCancelResult) { // The text of the button. string caption = _GetButtonCaption(buttonType); // Text must be not null. Debug.Assert(!string.IsNullOrEmpty(caption)); // Create button. MessageBoxExButton button = new MessageBoxExButton(); button.Caption = caption; // The return value in case this button is clicked. button.Value = buttonType; if (isCancelResult) button.IsCancelButton = true; // Add a custom button to the message box. _msgBox.Buttons.Add(button); }