Using ApplicationCommands

Dec 5, 2008 at 11:21 PM
I have created a ribbon with the standard clipboard buttons Cut/Copy & Paste.

There is also a TextBox control. The TextBox control knows about ApplicationCommands.

When the TextBox control has focus, I would like the buttons on the ribbon to work.

Is it possible to route ApplicationCommands instead of the RibbonCommands?
Dec 6, 2008 at 12:34 AM
The ribbon should work fully when the TextBox has Focus.  I just tested it out and I got a RibbonCommand to properly route when I clicked on a button and I had focus in a TextBox.  What commands are you seeing that are not functioning properly?

Currently due to implementation the Ribbon and its controls us RibbonCommands.
Dec 8, 2008 at 12:35 PM
Thanks for the reply.

An example of what we are trying to do:-

<r:RibbonWindow x:Class="WpfApplicationRouting.Window1"
    Title="Window1" Height="381" Width="627"  Background="White">
 <StackPanel FocusManager.FocusedElement="{Binding ElementName=text}">
    <r:RibbonCommand x:Key="AppCommands.Cut" x:Name="commandCut"
                           ToolTipDescription="Cut selected object to the Clipboard." CanExecute="commandCut_CanExecute" Executed="commandCut_Executed"  />
   <r:RibbonTab Label="Home">
    <r:RibbonGroup x:Name="clipboard">
     <r:RibbonButton Command="{StaticResource AppCommands.Cut}"/>
  <TextBox x:Name="text"></TextBox>


namespace WpfApplicationRouting
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : RibbonWindow
        public Window1()

        private void commandCut_CanExecute(object sender, CanExecuteRoutedEventArgs e)
            ICommand command = ApplicationCommands.Cut;

            e.CanExecute = command.CanExecute(null);

        private void commandCut_Executed(object sender, ExecutedRoutedEventArgs e)
            ICommand command = ApplicationCommands.Cut;




commandCut_Executed does not get called. (When you click on the button the focus is lost...)

The key is that we want controls to respond to ApplicationCommands not commands derived from RibbonControl.

Jan 5, 2009 at 7:33 PM

In order not to lose focus, you have to make the ribbon a FocusScope. All you need to do is set an attached property on the ribbon -  FocusManager.IsFocusScope="True"  .







Height="Auto" Width="Auto"






Title="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Window}},Path=Title}"















Jan 7, 2009 at 1:28 PM

Thank you for your reply.

I tried setting the IsFocusScope to true. Now the behaviour has changed when I get the canexecute event.

The originalsource is no longer the ribbon control.

How do I find out the source of the command?

Also after clicking on the buttton I want the focus to return back to where it was. Basically behave like a normal toolbar.





Jan 7, 2009 at 1:36 PM
Yes, we can get RibbonCommands to route correctly.

The problem is that we want an applicationcommand to be routed instead.

The workaround so far is to handle the RibbonCommand and then raise a new ApplicationCommand instead.


Jan 7, 2009 at 4:25 PM
I couldn't agree more. Using ApplicationCommands  or any routed commands is very clumsy at the moment ; you have to write dozens of little handlers that do nothing but redirect.  Very tedious and not elegant.  The whole point of routed commands was to reduce clutter .  I'll be disappointed if the ribbon ships with this architecture .
May 27, 2009 at 12:16 PM

I agree that it must be FocusManager.IsFocusScope="True" in order to keep focus on command target. You can see at post ID 52089 how you can use RibbonCommand with DelegateCommand which is part of MVVM template. Look at post of daywalker. Declaration of CommandReference must be something like:

<commands:CommandReference x:Key="CutCommandReference" Command="ApplicationCommands.Cut"/>

I use it with my custom static commands like ApplicationCommands and all works well.

Best regards!!!

Aug 3, 2009 at 11:24 AM

Hi John

I'm having problems getting the Cut, Copy, Paste Ribbon buttons to work. I've used the code you posted and the Cut button (for example) gets enabled when I select some text in the text box. But when I click the Cut ribbon button, the Cut ribbon button gets disabled and the Execute event is never raised.

You said in your previous Email that you had a workaround. Can you please post the work around, so I can see how to do it.


Many thanks



Aug 8, 2009 at 9:18 AM

Hi Mark,

I didn't look the code posted by John but as banko said you need to set FocusManager.IsFocusScope="True" for the Ribbon. This will keep input focus onto TextBox. Your Execute event is never raised because at the moment you click the button it will grab the focus and CanExecute for your Cut command will be false. I hope this help you.