从发送者执行的对象中获取RibbonCommand名称

时间:2009-10-21 12:09:35

标签: wpf command casting ribbon sender

如何获取已执行的Ribbon命令标签。信息存在于发送方对象中,但如何在RibbonCommand中进行转换,然后我可以获取该命令名称

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

但在这种情况下,rbnBmd仍然是空的。如何将发送方对象转换为功能区命令?

1 个答案:

答案 0 :(得分:0)

在这里你走人

  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是你的类,扩展Window意味着MainWindow:Window 正式你的Window1