NavBarItemLink Class
A link to a NavBarItem.
Namespace: DevExpress.XtraNavBar
Assembly: DevExpress.XtraNavBar.v24.2.dll
NuGet Package: DevExpress.Win
#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.
#Example
This example creates a NavBarControl
in code and adds a Local group with three commands (“Inbox”, “Sent Items”, and “Spam”) to the NavBarControl
.
- Create a
NavBarControl
instance. - Create a NavBarGroup instance and add it to the NavBarControl.Groups collection.
For commands, create NavBarItem objects. Use the ImageOptions property to specify an image for each command. Add the commands to the NavBarGroup.ItemLinks collection.
Tip
You can use Nav
Bar and NavControl. Begin Update Bar methods to prevent excessive updates when multiple properties are modified.Control. End Update - Handle the NavBarControl.LinkClicked event to respond to clicks on commands.
Note
svg
was created and populated at runtime.
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));
}