Linking a Ribbon Button to a .Net Command

Linking a Ribbon Button to a .Net Command

JamesLH88
Explorer Explorer
10,973 Views
22 Replies
Message 1 of 23

Linking a Ribbon Button to a .Net Command

JamesLH88
Explorer
Explorer

Hi All,

 

I wonder if anybody can help me.

 

I have a few commands that I have created, and they work great if called via the command line.

 

[CommandMethod("MyCommand", CommandFlags.UsePickSet | CommandFlags.Redraw | CommandFlags.Modal)]
public void MyCommandFunction()
{
       // MY CODE IS HERE
}

I have also created a new ribbon tab, with panel, and RibbonButton, and assigned a CommandHandler which calls a Action (callback function). However, I can't seem to get my button to trigger 'MyCommand'.

 

RibbonCommandHandler ActionHandler = new RibbonCommandHandler();
ActionHandler.CallBack = CallBackFunction;
myButton.Id = "MyButtonID";
myButton.CommandHandler = ActionHandler;


public class RibbonCommandHandler : System.Windows.Input.ICommand
{
    public Action<String> CallBack;
    public event EventHandler CanExecuteChanged;

    public bool CanExecute(object parameter)
    {
        return true;
    }

    public void Execute(object parameter)
    {
        if (parameter is RibbonButton)
        {
            RibbonButton button = parameter as RibbonButton;
            CallBack(button.Id);
        }
    }
}


public void CallBackFunction(String message)
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
            
    switch (message)
    {
        case "MyButtonID":
            // I AM STUCK HERE .....
            break;
    }
}

 

Apologies if I have failed to explain my problem very clearly. I am not sure if I am even going around the issue the right way. But any assistance to point me in the right direction would be greatly appreciated!

 

 

Thanks,

James

 

 

 

 

 

0 Likes
Accepted solutions (2)
10,974 Views
22 Replies
Replies (22)
Message 21 of 23

TiStars
Advisor
Advisor
Hi, sorry for disturbing you again, I wonder if you know any docs about making installer for AutoCAD? is it same with making a normal installer of window software like setup.exe etc? Thank you very much

天涯海角的山姆


您认为此帖子是否有用?欢迎为此帖点赞。

您的问题是否已得到解答?请点击“接受解答”按钮。


EESignature



0 Likes
Message 22 of 23

ActivistInvestor
Mentor
Mentor

@TiStars wrote:
Hi, sorry for disturbing you again, I wonder if you know any docs about making installer for AutoCAD? is it same with making a normal installer of window software like setup.exe etc? Thank you very much

You can see > this document <

0 Likes
Message 23 of 23

TiStars
Advisor
Advisor
Many many thanks!!!

天涯海角的山姆


您认为此帖子是否有用?欢迎为此帖点赞。

您的问题是否已得到解答?请点击“接受解答”按钮。


EESignature



0 Likes