功能区控件的命令绑定

时间:2009-07-16 06:05:56

标签: c# wpf ribbon-control

我正在尝试使用C#以编程方式使用Microsoft功能区控件。一切都很好,但我无法通过RibbonCommand绑定命令。谁能给我一个如何做到这一点的例子?我的实际代码是:

            Ribbon rbn = new Ribbon();

            RibbonTab file = new RibbonTab();
            file.Name = "file";
            file.Label = "FILE";

            RibbonTab edit = new RibbonTab();
            edit.Name = "edit";
            edit.Label = "Edit";

            RibbonGroupPanel rbgp = new RibbonGroupPanel();
            RibbonGroup rbg = new RibbonGroup();

            RibbonButton rbtn = new RibbonButton();
            rbtn.Content = "New";

            RibbonCommand rcomnd = new RibbonCommand();

            rcomnd.LabelTitle = "NEW";
            rcomnd.ToolTipDescription = "THIS IS NEW";
            rcomnd.LargeImageSource = imgSource;


            rcomnd.Execute(rbtn, rbtn);

            rbtn.IsEnabled = true;
            //rcomnd.SmallImageSource = imgSource;

           rcomnd.CanExecute +=new CanExecuteRoutedEventHandler(rcomnd_CanExecute);
           rcomnd.Executed +=new ExecutedRoutedEventHandler(rcomnd_Executed);

           CommandBinding cmdb = new CommandBinding(ApplicationCommands.New);
           cmdb.Command = ApplicationCommands.New;

            cmdb.Executed +=new ExecutedRoutedEventHandler(cmdb_Executed);
            CommandBind.Add(cmdb);
           //rcomnd.Executed += new ExecutedRoutedEventHandler(OnAddNewEntry);*/

            rbtn.Click +=new System.Windows.RoutedEventHandler(rbtn_Click);
             rbtn.Command = rcomnd;

但绑定不起作用且按钮未启用。

1 个答案:

答案 0 :(得分:1)

从“添加命令”部分检查this tutorial。从一开始就读它可能会很好。