Input Bindings and Tooltip on Ribbon Buttons

Ribbon for WPF Forum

Posted 8 years ago by Hamid Noorbakhsh
Version: 16.1.0633
Avatar

I am using Ribbon and my Gestures correctly show on the RibbonButton. I have a few that use the 'Shift' as modifier key and I have to go the route of InputBinding. I am adding them correctly AND they are working fine, the only issue is to get them in the 'ScreenTip' automatically(?) as the gestures work perfect.

If this is not already part of the control, is there a workaround without me having to add these statically? 

Comments (4)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Hamid,

You can set the button's InputGestureText to specify your own gesture string as needed.


Actipro Software Support

Posted 8 years ago by Hamid Noorbakhsh
Avatar

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?

Answer - Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Hamid,

Maybe you could inherit RibbonCommand and add a property for InputGestureText on that and then bind to it like:

<apribbon:Button Command="tbcommands:TaskBuilderRoutedCommands.ExpandRegions"
    InputGestureText="{x:Static tbcommands:TaskBuilderRoutedCommands.ExpandRegions.InputGestureText}" />

Then just make that InputGestureText property non-null if it's the one scenario you're having trouble with.


Actipro Software Support

Posted 8 years ago by Hamid Noorbakhsh
Avatar

Thank you, I figured I would have to do something like that to keep the entire project sort of dynamic where everything is defined in one place.

The latest build of this product (v24.1.2) was released 2 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.