command binding for ribbon control

Posted by kartik on Stack Overflow See other posts from Stack Overflow or by kartik
Published on 2009-07-16T06:05:55Z Indexed on 2010/04/08 1:03 UTC
Read the original article Hit count: 966

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about c#