Back to Devexpress

NavBarItemLink Class

windowsforms-devexpress-dot-xtranavbar-c1f03ae7.md

latest7.8 KB
Original Source

NavBarItemLink Class

A link to a NavBarItem.

Namespace : DevExpress.XtraNavBar

Assembly : DevExpress.XtraNavBar.v25.2.dll

NuGet Package : DevExpress.Win

Declaration

csharp
public class NavBarItemLink :
    ICollectionItem,
    IDisposable
vb
Public Class NavBarItemLink
    Implements ICollectionItem,
               IDisposable

The following members return NavBarItemLink objects:

Show 13 links

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.

Example

This example creates a NavBarControl in code and adds a Local group with three commands (“Inbox”, “Sent Items”, and “Spam”) to the NavBarControl.

  1. Create a NavBarControl instance.

  2. Create a NavBarGroup instance and add it to the NavBarControl.Groups collection.

  3. For commands, create NavBarItem objects. Use the ImageOptions property to specify an image for each command. Add the commands to the NavBarGroup.ItemLinks collection.

  4. Handle the NavBarControl.LinkClicked event to respond to clicks on commands.

Note

svgImageCollection1 was created and populated at runtime.

csharp
using DevExpress.XtraNavBar;

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";
  // Create a Local group.
  NavBarGroup groupLocal = new NavBarGroup("Local");
  // Create an Inbox item and assign an image.
  NavBarItem itemInbox = new NavBarItem("Inbox");
  itemInbox.ImageOptions.SvgImage = svgImageCollection1["inbox"];
  // Create a disabled Sent Items item.
  NavBarItem itemSentItems = new NavBarItem("Sent Items");
  itemSentItems.ImageOptions.SvgImage = svgImageCollection1["sent-items"];
  itemSentItems.Enabled = false;
  // Create a Spam item.
  NavBarItem itemSpam = new NavBarItem("Spam");
  itemSpam.ImageOptions.SvgImage = svgImageCollection1["spam"];
  // Add the items to the group and add the group to the NavBarControl.
  // Prevent excessive updates using BeginUpdate and EndUpdate methods.
  navBar.BeginUpdate();
  navBar.Groups.Add(groupLocal);
  groupLocal.ItemLinks.Add(itemInbox);
  groupLocal.ItemLinks.Add(itemSentItems);
  groupLocal.ItemLinks.Add(itemSpam);
  groupLocal.Expanded = true;
  navBar.EndUpdate();
  // Handle the NavBarControl's LinkClicked event.
  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));
}
vb
Imports DevExpress.XtraNavBar

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
  ' Create a NavBarControl.
  Dim navBar As New NavBarControl()
  Me.Controls.Add(navBar)
  navBar.Dock = DockStyle.Fill
  ' Apply the "SkinExplorerBarView" style.
  navBar.PaintStyleName = "SkinExplorerBarView"
  ' Create a Local group.
  Dim groupLocal As New NavBarGroup("Local")
  ' Create an Inbox item and assign an image.
  Dim itemInbox As New NavBarItem("Inbox")
  itemInbox.ImageOptions.SvgImage = svgImageCollection1("inbox")
  ' Create a disabled Sent Items item.
  Dim itemSentItems As New NavBarItem("Sent Items")
  itemSentItems.ImageOptions.SvgImage = svgImageCollection1("sent-items")
  itemSentItems.Enabled = False
  ' Create a Spam item.
  Dim itemSpam As New NavBarItem("Spam")
  itemSpam.ImageOptions.SvgImage = svgImageCollection1("spam")
  ' Add the items to the group and add the group to the NavBarControl.
  ' Prevent excessive updates using BeginUpdate and EndUpdate methods.
  navBar.BeginUpdate()
  navBar.Groups.Add(groupLocal)
  groupLocal.ItemLinks.Add(itemInbox)
  groupLocal.ItemLinks.Add(itemSentItems)
  groupLocal.ItemLinks.Add(itemSpam)
  groupLocal.Expanded = True
  navBar.EndUpdate()
  ' Handle the NavBarControl's LinkClicked event.
  AddHandler navBar.LinkClicked, AddressOf navBar_LinkClicked
End Sub

Private Sub navBar_LinkClicked(ByVal sender As System.Object, ByVal e As NavBarLinkEventArgs)
    MessageBox.Show(String.Format("The {0} link has been clicked", e.Link.Caption))
End Sub

Implements

ICollectionItem

Inheritance

Object NavBarItemLink

See Also

NavBarItemLink Members

ItemLinks

Groups

Items

NavBarGroup

NavBarItem

DevExpress.XtraNavBar Namespace