RoutedUICommands in ApplicationMenu

Ribbon for WPF Forum

Posted 10 years ago by Owen Christensen - Software Engineer, Minitab Inc.
Version: 4.5.0485
Avatar
System: .NET 3.5, Windows Vista, 64-bit

            RibbonCommandUIProvider provider = new RibbonCommandUIProvider("New", null as string, null as string);
            RibbonCommandUIManager.Register(FindResource("NewCommand") as ICommand, provider);

        private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }

<ribbon:RibbonWindow.Resources>
        <RoutedUICommand x:Key="NewCommand" Text="New"/>
    </ribbon:RibbonWindow.Resources>
    
    <ribbon:RibbonWindow.InputBindings>
        <KeyBinding Command="{StaticResource NewCommand}" Gesture="CTRL+N"/>
    </ribbon:RibbonWindow.InputBindings>
    
    <ribbon:RibbonWindow.CommandBindings>
        <CommandBinding Command="{StaticResource NewCommand}" CanExecute="CommandBinding_CanExecute" Executed="CommandBinding_Executed"/>
    </ribbon:RibbonWindow.CommandBindings>
    
    <ribbon:Ribbon>
        <ribbon:Ribbon.ApplicationMenu>
            <ribbon:ApplicationMenu>
                <ribbon:Button Command="{StaticResource NewCommand}"/>
            </ribbon:ApplicationMenu>
        </ribbon:Ribbon.ApplicationMenu>
    </ribbon:Ribbon>
The ScreenTip never appears on the button if the ScreenTipDescription is not set if using RibbonCommandUIManager.Register.
Moreover even if the description is set, the Input Binding does not show up in the header automatically like it does if I use a RibbonCommand.

Comments (3)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Owen,

First, when using RibbonCommandUIManager.Register, it must be called before any UI is loaded. Therefore if you want a command in the resources of something, it can only reside in the Application's resources.

Screen tips are smart and won't display unless you set some specific screentip property. For instance, on a menu item where it shows "New", why show a screen tip that just has "New" in it? Now that being said, if it find a set ScreenTipHeader, or other screentip property, it will show the screen tip.

It can't find the keyboard shortcut in this case though because you set the gesture on the window's input bindings. If you put it on the command itself, it should find and display it.

Hope that helps!


Actipro Software Support

Posted 10 years ago by Owen Christensen - Software Engineer, Minitab Inc.
Avatar
How do I put it on the command itself? There are no such properties on RoutedUICommand (and rightly so as commands may never be associated with input bindings.)
Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Owen,

RoutedCommand has an InputGestures collection:
http://msdn.microsoft.com/en-us/library/system.windows.input.routedcommand.inputgestures.aspx

However as mentioned in that topic, it can't be set in XAML. So you must create your command in code, or alternatively at least assign the KeyGesture in code.


Actipro Software Support

The latest build of this product (v2018.1 build 0675) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.