
Well I am doing this though Binding: Her eis the xaml:
<apribbon:Menu apribbon:Menu.IsMenuItemInputGestureTextVisible="True">
<apribbon:Button Command="tbcommands:TaskBuilderRoutedCommands.ExpandRegions" />
<apribbon:Button Command="tbcommands:TaskBuilderRoutedCommands.CollapseRegions" />
</apribbon:Menu>
Then here is the command:
private static RibbonCommand m_ExpandRegions;
public static RibbonCommand ExpandRegions
{
get
{
if (m_ExpandRegions == null)
{
m_ExpandRegions = new RibbonCommand("ExpandRegions", typeof(Ribbon), R.ExpandRegions,
null, string.Empty);
InputBindingsManager.CommandInputBindings.Add(m_ExpandRegions, new KeyBinding { Key = Key.E, Modifiers = ModifierKeys.Shift });
}
return m_ExpandRegions;
}
}
Unfortunately the Shift Modifier will not let me add it as gesture as such:
m_ExpandRegion.InputGestures.Add(new KeyGesture(Key.E, ModifierKeys.Shift)); < Does not work
But I add the CommandBinding with attached behavior as you had suggested, and I also handle the InputBinding (KeyBinding), except I need the Text for the KeyBinding to show the MenuItem. I do not want to add in xaml UNLESS I can bind it to something.
private static void OnRegisterCommandBindingChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
UIElement element = sender as UIElement;
if (element != null)
{
CommandBindingCollection bindings = e.NewValue as CommandBindingCollection;
if (bindings != null)
{
foreach (CommandBinding binding in bindings)
{
element.CommandBindings.Add(binding);
if (InputBindingsManager.CommandInputBindings.ContainsKey(binding.Command))
{
element.InputBindings.Add(InputBindingsManager.CommandInputBindings[binding.Command]);
//InputBindingsManager.CommandInputBindings.Remove(binding.Command);
}
}
}
}
}
Everything works fine as far as I can see except to pull the KeyBinding and sticking it in the MenuItem same as Gestures.
If you can give me a quick hint, or it can not be done this way? forcing me to put it in xaml?