[英]command binding for ribbon control
I'm trying to use the Microsoft ribbon control programatically using C#. 我正在尝试通过C#以编程方式使用Microsoft功能区控件。 Everything is fine but I'm unable to bind the command through the RibbonCommand. 一切都很好,但是我无法通过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. 但是绑定不起作用,并且按钮未启用。
Check this tutorial from the "Adding Commands" section. 从“添加命令”部分检查本教程 。 It may be good to read it from the start. 从头开始阅读它可能会很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.