功能区控件的命令绑定

发布于 2024-07-26 16:52:37 字数 1549 浏览 4 评论 0原文

我正在尝试使用 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;

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

I'm trying to use the Microsoft ribbon control programatically using C#. Everything is fine but I'm unable to bind the command through the RibbonCommand. Can anyone give me an example of how to do this? My actual code is:

            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;

But the bindings are not working and the button is not enabled.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我的痛♀有谁懂 2024-08-02 16:52:37

从“添加命令”中查看本教程部分。 从头开始阅读可能会很好。

Check this tutorial from the "Adding Commands" section. It may be good to read it from the start.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文