MenuItemhas a property InputGestureText, when it is not installed, it checks to see if the item Command RoutedCommandis and displays a display string for the first KeyGestureone that it can find.
( RoutedCommand):
public class RoutedCommandToInputGestureTextConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
RoutedCommand command = value as RoutedCommand;
if (command != null)
{
InputGestureCollection col = command.InputGestures;
if ((col != null) && (col.Count >= 1))
{
for (int i = 0; i < col.Count; i++)
{
KeyGesture keyGesture = ((IList)col)[i] as KeyGesture;
if (keyGesture != null)
{
return keyGesture.GetDisplayStringForCulture(CultureInfo.CurrentCulture);
}
}
}
}
return Binding.DoNothing;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return Binding.DoNothing;
}
}
:
<Window.Resources>
<ResourceDictionary>
<local:RoutedCommandToInputGestureTextConverter x:Key="RoutedCommandToInputGestureTextConverter" />
</ResourceDictionary>
</Window.Resources>
<Grid>
<Button
Content="Save"
Command="Save"
ToolTip="{Binding Command, RelativeSource={RelativeSource Self}, Converter={StaticResource RoutedCommandToInputGestureTextConverter}}"
ToolTipService.ShowOnDisabled="True" />
</Grid>