Ribbon KeyGesture EventHandler

Dec 30, 2008 at 5:03 PM
I have added a KeyGesture for a RibbonCommand and I have only one ExecutedRoutedEventHanlder for all ribbons.

In the callback function I use the OriginalSource property to know which button is pressed.
When the user press the key the OriginalSource isn't the RibbonButton but it is the Window, why ?
How can I know what is the RibbonButton connected with ?

            RibbonButton ribButton = (RibbonButton)e.OriginalSource;
            switch (ribButton.Name)
            {
            }

Thank you very much
Marco
Feb 5, 2009 at 3:49 PM
I have exactly the same problem.

I have a ribbon control and a data grid in my window. If I select a cell in the data grid and then press a ribbon button. The original source property is then set to the selected cell in the data grid. When I press the ribbon button before I select a cell, the original source property is set to the button.
From my understanding of RoutedEvents, this shouldn't be possible, because the ribbon control and data grid are not on the same path of the visual tree!

Has anybody a solution for this problem?
Any help will be appreciated.
Feb 12, 2009 at 2:56 PM
Does nobody know any solution or workaround?
Feb 18, 2009 at 7:47 AM
I've found a workaround for that problem.
I hooked up both the PreviewExecuted and Executed event. They have both the same event handling method. In the PreviewExecuted event, the OriginalSource property has the correct value.
In the event handling handler I change the property Handled to true. So the Executed event won't fire, if the PreviewExecuted event was handled properly. I had to hook up both events, because when I just registered the PreviewExecuted event, all ribbon buttons were disabled.