简体   繁体   中英

command binding for ribbon control

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM