UI Elements in CAB

CAB has a special way to deal with UI elements in applications.  It has a means to register certain UI elements, which you can then reference them by name.  Why is that more beneficial?  Let's take a look at how you can register a ToolStripMenuItem in a drop down.  I'm going to add these in the program class that inherits from FormShellApplication that I mentioned about.  In this class, I will be overriding the AfterShellCreated method, which is run after the setup of the shell form.

protected override void AfterShellCreated()
{
   base.AfterShellCreated();

   //File is the file menu; tsiFile is the UI object
   this.RootWorkItem.UIExtensionSites.RegisterSite("File", this.Shell.tsiFile);
   //Must register dropdowns to add items to the drop down list
   this.RootWorkItem.UIExtensionSites.RegisterSite("File_DropDown", this.Shell.tsiFile.DropDownItems);
   //Add additional items
}

So the UIExtensionSites provides a means to site new items, to get the existing UI items that have been sited, etc.  Once these items are sited, we can also link to their events through commands.  Commands are a way to receive the events of a UI sited item.  For instance, if we have a method called File_Click, you can add a CommandHandler attribute to it as such:

[CommandHandler("FileClicked")]
public void File_Click(object sender, EventArgs e) {..}

Then, you can register an event handler to fire this event, using the UI item:

this.RootWorkItem.Commands("FileClicked").AddInvoker(this.Shell.tsiFile, "Click");

When the item in the UI is clicked, it fires this custom event handler because it is linked to the command.  Why is this beneficial?  Because you can define the event handlers in various places, not necessarily linked directly through adding an event handler to the Click event.  You can define the event handler in a controller instead of directly in the file, making it more modularized.

You can also enable/disable/hide items linked to a command.  The command has a status of Enabled/Disabled/Unavailable, which enables, disables, or hides the item associated with the command.

Comments

No Comments

The leading UI suite for ASP.NET - Telerik radControls
Outstanding performance. Full ASP.NET AJAX support. Nearly codeless development.