/// <summary> /// Occurs when the <see cref="RoutedCommand"/> is executed. /// </summary> /// <param name="sender">The sender of the event.</param> /// <param name="e">An <see cref="ExecutedRoutedEventArgs"/> that contains the event data.</param> private void OnFontFamilyExecute(object sender, ExecutedRoutedEventArgs e) { FontFamilyValueCommandParameter parameter = e.Parameter as FontFamilyValueCommandParameter; if (parameter != null) { if ((parameter.Value != null) && (!RibbonControls.FontFamilyComboBox.IsValidFontFamilyName(parameter.Value.Source))) { MessageBox.Show(String.Format("The font family '{0}' does not exist.", parameter.Value), "Invalid Font Family", MessageBoxButton.OK, MessageBoxImage.Exclamation); } else { switch (parameter.Action) { case ValueCommandParameterAction.CancelPreview: this.DeactivatePreviewMode(true); break; case ValueCommandParameterAction.Commit: this.DeactivatePreviewMode(false); this.SelectionFontFamily = parameter.Value; break; case ValueCommandParameterAction.Preview: this.ActivatePreviewMode(); this.SelectionFontFamily = parameter.PreviewValue; break; } } e.Handled = true; } }
/// <summary> /// Occurs when the <see cref="RoutedCommand"/> needs to determine whether it can execute. /// </summary> /// <param name="sender">The sender of the event.</param> /// <param name="e">A <see cref="CanExecuteRoutedEventArgs"/> that contains the event data.</param> private void OnFontFamilyCanExecute(object sender, CanExecuteRoutedEventArgs e) { FontFamilyValueCommandParameter parameter = e.Parameter as FontFamilyValueCommandParameter; if ((parameter != null) && (!this.IsPreviewModeActive)) { parameter.UpdatedValue = this.SelectionFontFamily; parameter.Handled = true; } e.CanExecute = true; }