// Gets the input gesture text from the command text if it hasn't been explicitly specified private static object CoerceInputGestureText(DependencyObject d, object value) { ButtonBase button = (ButtonBase)d; RoutedCommand routedCommand; if (string.IsNullOrEmpty((string)value) && !button.HasNonDefaultValue(InputGestureTextProperty) && (routedCommand = button.Command as RoutedCommand) != null) { InputGestureCollection col = routedCommand.InputGestures; if ((col != null) && (col.Count >= 1)) { // Search for the first key gesture for (int i = 0; i < col.Count; i++) { KeyGesture keyGesture = ((IList)col)[i] as KeyGesture; if (keyGesture != null) { return(keyGesture.GetDisplayStringForCulture(CultureInfo.CurrentCulture)); } } } } return(value); }
// Set the label to the command text if no label has been explicitly specified private static object CoerceLabel(DependencyObject d, object value) { ButtonBase button = (ButtonBase)d; RoutedUICommand uiCommand; // If no label has been set, use the command's text if (string.IsNullOrEmpty(value as string) && !button.HasNonDefaultValue(LabelProperty)) { uiCommand = button.Command as RoutedUICommand; if (uiCommand != null) { value = uiCommand.Text; } return(value); } return(value); }