NavBarItemLink Class

A link to a NavBarItem.

Namespace: DevExpress.XtraNavBar

Assembly: DevExpress.XtraNavBar.v20.1.dll

Declaration

Remarks

In order to display the contents of an item within a group, one must create a link to the item. Each group stores its collection of links represented by the NavBarGroup.ItemLinks property. This property returns the NavLinkCollection class whose methods can be used to add, delete and move links within the collection. You can also use this object's NavLinkCollection.Item property to access an individual link.

Properties of the NavBarItemLink class return the corresponding settings of the linked item. The item that is referred to by this object can be obtained via the NavBarItemLink.Item property.

Examples

The following code shows how to create a NavBarControl in code. One group (Local) is added to the control containing three commands ("Inbox", "Outbox" and "Sent Items").

In the example, NavBarItem objects are created to represent the required commands. Their NavElement.Caption properties are initialized appropriately. These specify the display text for the items.

It's assumed that small images for NavBar items are stored in the imageList1 component. To use these images, the imageList1 is assigned to the NavBarControl.SmallImages property. Then images from the list are associated with specific NavBar items via the item's NavElement.SmallImageIndex property.

The NavBarControl.BeginUpdate and NavBarControl.EndUpdate methods are used to prevent excessive updates when mutiple control's properties are modified.

The image below shows the result:

NavBarControl_Create_Ex

using DevExpress.XtraNavBar;

private void Form1_Load(object sender, EventArgs e) {
    // Create a NavBarControl.
    NavBarControl navBar = new NavBarControl();
    this.Controls.Add(navBar);
    navBar.Dock = DockStyle.Fill;
    // Apply the "SkinExplorerBarView" style.
    navBar.PaintStyleName = "SkinExplorerBarView";
    // Assign the list that stores small images to the control.
    navBar.SmallImages = imageList1;
    // Create a Local group.
    NavBarGroup groupLocal = new NavBarGroup("Local");
    // Create an Inbox item and assign an image from the SmallImages list to the item.
    NavBarItem itemInbox = new NavBarItem("Inbox");
    itemInbox.SmallImageIndex = 0;            
    // Create an Outbox item.
    NavBarItem itemOutbox = new NavBarItem("Outbox");
    itemOutbox.SmallImageIndex = 1;
    // Create a disabled Sent Items item.
    NavBarItem itemSentItems = new NavBarItem("Sent Items");
    itemSentItems.SmallImageIndex = 2;
    itemSentItems.Enabled = false;
    // Add the created items to the group and the group to the NavBarControl.
    // Prevent excessive updates using the BeginUpdate and EndUpdate methods.
    navBar.BeginUpdate();
    navBar.Groups.Add(groupLocal);
    groupLocal.ItemLinks.Add(itemInbox);
    groupLocal.ItemLinks.Add(itemOutbox);
    groupLocal.ItemLinks.Add(itemSentItems);
    groupLocal.Expanded = true;
    navBar.EndUpdate();
    // Specify the event handler which will be invoked when any link is clicked.
    navBar.LinkClicked += new NavBarLinkEventHandler(navBar_LinkClicked);
}

void navBar_LinkClicked(object sender, NavBarLinkEventArgs e) {
    MessageBox.Show(string.Format("The {0} link has been clicked", e.Link.Caption));
}

Implements

Inheritance

Object
NavBarItemLink
See Also