views:

81

answers:

1

How to get the Label of Ribbon command that is executed. Information is present in sender object but how to cast it in RibbonCommand and then I can get that command name

 private void RibbonCommand_Executed(object sender, ExecutedRoutedEventArgs e)
    {
RibbonCommand rbnCmd = sender as RibbonCommand;
}

But in this case rbnBmd remains empty. How to cast sender object into ribbon command ?

A: 

Here You Go Man

  private void RibbonCommand_Executed(object sender, ExecutedRoutedEventArgs e)
    {
        MainWindow m = (MainWindow)sender;
        RibbonGroup rbnGrp = m.DiscoveryGroup;
        RibbonCommand rbnCmd = (RibbonCommand)rbnGrp.Command;
        string clickedCmd = rbnCmd.LabelTitle;

MainWindow is your class that extends Window means MainWindow:Window formally your Window1

Aizaz
But how to get X:key of clicked command ? is still an issue'<r:RibbonCommand Executed="RibbonCommand_Executed" x:Key="cmdPrint" LabelTitle="Print" ToolTipTitle="Print" ToolTipDescription="This is used to Print" SmallImageSource="Images\printIcon.png" LargeImageSource="Images\printIcon.png" />'
Aizaz