I am using Ribbon with a CAB application. We want the Ribbon in a View(not in the shell). but it comes out like in the attached file. with 2 form heads. We want the Ribbon's application menu and not the shells. Is a way to do this? If I put the Ribbon in shell, it comes out fine. but we don't want all toolbar handling in the ShellForm.cs. That is too much code there.
Do u have an good example to look for this? All CAB & Ribbon examples shows how to register Ribbon as UIExtension, but how to handle the clicks?
Thanks,
In the demo I have sent you (see: the post) I have shown you how to respond to click events on the ribbon tool buttons from the module that inserted the tool.
If you have a look at the ModuleController class in the NewToolbar.Module you can see how we hooked the ToolClick event on a ToolButton:
WorkItem.Commands[CommandNames.RibbonFirstButtonClick].AddInvoker(button1, "ToolClick");
The event handler, which in CAB world is called a CommandHandler, you can find in the same ModuleController class:
[CommandHandler(CommandNames.RibbonFirstButtonClick)]
public void OnRibbonFirstButtonClick(object sender, EventArgs eventArgs)
{
MessageBox.Show(string.Format("Raised command's name: {0}", CommandNames.RibbonFirstButtonClick));
}
yes, that one helped a lot. But I can only add tools to ribbon like in runtime, not in design. My question now is:
is it possible i don't register Ribbon as UIExtension? I want it in a view that I can add tools at design but show it in the Shell. So the application button will cover the Shell Form's header.
Thanks, I just copy and paste the one in support request to the first post.
I am thinking that maybe you do not need to use the CAB infrastructure.
If you are adding the ToolButtons a module uses in the Shell, you are killing the modularity CAB provides. The reason UIExtension are present in a CAB application si to be able to add the necessary controls a module requires in a central place, as the Ribbon is, or any other toolbar, menu, etc.
What will happen to the ToolButtons on the ribbon if the module connected to them will not be loaded?
On the other hand, you can add the ribbon, or the individual ToolButtons to the Items collection in the RootWorkItem so they should be available anywhere in your application. This way you can hook to the ToolClick event in the module you are suppose to:
- in ShellApplication class, you cand add the following code to the AfterShellCreated method:
RootWorkItem.Items.Add(Shell.Ribbon, "Ribbon");
the Ribbon should be a get property in the Shell which return the reference to the ribbon, just as you can find in the exemple I've provided.
- then in your module, whenever you have access to the WorkItem (like Module class, ModuleController class, Presenters class), you can get a hold on the Ribbon and hook the ToolClick event on the desired ToolButton. In the ModuleController class, in the Run method you can add:
Ribbon ribbon = (Ribbon) WorkItem.RootWorkItem.Items["Ribbon"];
ribbon.Tabs[tabIndex].Groups[groupIndex].Tools[toolIndex].ToolClick += OnDesiredButtonToolClick;
this way you add a hook to the ToolClick event on the ToolButton you desire. So you have to creade the event handler method:
private void OnDesiredButtonToolClick(object sender, ToolClickEventArgs e)
// code to handle the ToolClick event
HTH,
Emanuel