Skip to main content

NavigationBarItemCollection

Namespace: Wisej.Web.Ext.NavigationBar

Assembly: Wisej.Web.Ext.NavigationBar (4.1.0.0)

Contains a collection of NavigationBarItem objects.

public class NavigationBarItemCollection : IList, ICollection, IEnumerable, IList<NavigationBarItem>, ICollection<NavigationBarItem>, IEnumerable<NavigationBarItem>

Properties​

Instance member Count​

Int32: Returns the number of items in the collection.

Value: The number of items in the collection.

Instance member Item(index)​

NavigationBarItem: Returns or sets a NavigationBarItem in the collection at the specified index.

Value: The NavigationBarItem at the specified index.

Setting an item replaces the existing item at index , which is removed from the collection but not disposed.

Throws:

Example:

Replacing the first item:

this.navigationBar1.Items[0] = new NavigationBarItem { Name = "home", Text = "Home", Icon = "Images/home.svg" };

Instance member Item(name)​

NavigationBarItem: Returns the NavigationBarItem with the specified key from the collection.

Value: The NavigationBarItem with the specified key.

Returns null when an item with the specified name is not found. The search is not recursive: only the items in this collection are searched.

Example:

Retrieving an item by name:

var reports = this.navigationBar1.Items["reports"];
if (reports != null)
reports.Expanded = true;

Methods​

Instance member Add(item)​

Adds a NavigationBarItem to the collection.

ParameterTypeDescription
itemNavigationBarItemThe NavigationBarItem to add.

Throws:

Example:

Adding an item created in code:

var item = new NavigationBarItem
{
Name = "inbox",
Text = "Inbox",
Icon = "Images/inbox.svg",
InfoText = "5"
};
this.navigationBar1.Items.Add(item);

Instance member Add(text)​

Creates a NavigationBarItem with the specified text, and adds it to the collection.

ParameterTypeDescription
textStringThe text to display on the NavigationBarItem.

Example:

Adding an item with only a title:

this.navigationBar1.Items.Add("Help");

Instance member Add(key, text)​

Creates a NavigationBarItem with the specified key and text and adds it to the collection.

ParameterTypeDescription
keyStringThe name of the NavigationBarItem.
textStringThe text to display on the NavigationBarItem.

Example:

Adding an item that can be retrieved by name:

this.navigationBar1.Items.Add("help", "Help");
this.navigationBar1.Items["help"].Icon = "Images/help.svg";

Instance member Add(key, text, icon)​

Creates a NavigationBarItem with the specified key, text, and image, and adds it to the collection.

ParameterTypeDescription
keyStringThe name of the NavigationBarItem.
textStringThe text to display on the NavigationBarItem.
iconStringThe Url or name of the icon to display on the NavigationBarItem.

Example:

Adding an item with an icon:

this.navigationBar1.Items.Add("settings", "Settings", "Images/settings.svg");

Instance member AddRange(items)​

Adds a set NavigationBarItem objects to the collection.

ParameterTypeDescription
itemsNavigationBarItem[]An array of type NavigationBarItem that contains the NavigationBarItem to add.

Throws:

Example:

Adding several items at once:

this.navigationBar1.Items.AddRange(new[]
{
new NavigationBarItem { Name = "dashboard", Text = "Dashboard", Icon = "Images/dashboard.svg" },
new NavigationBarItem { Name = "orders", Text = "Orders", Icon = "Images/orders.svg" },
new NavigationBarItem { Name = "customers", Text = "Customers", Icon = "Images/customers.svg" }
});

Instance member Clear()​

Removes all the NavigationBarItem instances from the collection.

The removed items are not disposed. Use Clear to dispose them.

Example:

Removing all the items before rebuilding the menu:

this.navigationBar1.Items.Clear();
this.navigationBar1.Items.Add("home", "Home", "Images/home.svg");

Instance member Clear(dispose)​

Removes all the NavigationBarItem instances from the collection and optionally disposes them.

ParameterTypeDescription
disposeBooleanIndicates whether to dispose the NavigationBarItem instances removed from the collection.

Example:

Removing and disposing all the items:

this.navigationBar1.Items.Clear(true);

Instance member Contains(item)​

Determines whether a specified NavigationBarItem is in the collection.

ParameterTypeDescription
itemNavigationBarItemThe NavigationBarItem to locate in the collection.

Returns: Boolean. true if the specified NavigationBarItem is in the collection; otherwise, false.

Throws:

Example:

Checking whether an item is a top-level item:

if (this.navigationBar1.Items.Contains(this.navigationBar1.SelectedItem))
AlertBox.Show("Top-level item selected.");

Instance member ContainsKey(key)​

Determines whether the collection contains a NavigationBarItem with the specified key.

ParameterTypeDescription
keyStringThe name of the NavigationBarItem to search for.

Returns: Boolean. true to indicate a NavigationBarItem with the specified key was found in the collection; otherwise, false.

Example:

Adding an item only once:

if (!this.navigationBar1.Items.ContainsKey("admin"))
this.navigationBar1.Items.Add("admin", "Administration", "Images/admin.svg");

Instance member CopyTo(array, index)​

Copies the NavigationBarItem instances in the collection to the specified array, starting at the specified index.

ParameterTypeDescription
arrayNavigationBarItem[]The one-dimensional array that is the destination of the items copied from the collection. The array must have zero-based indexing.
indexInt32The zero-based index in the array at which copying begins.

Throws:

Example:

Copying the items to an array:

var items = new NavigationBarItem[this.navigationBar1.Items.Count];
this.navigationBar1.Items.CopyTo(items, 0);

Instance member IndexOf(item)​

Returns the index of the NavigationBarItem in the collection.

ParameterTypeDescription
itemNavigationBarItemThe NavigationBarItem to locate in the collection.

Returns: Int32. The zero-based index of the item; -1 if it cannot be found.

Throws:

Example:

Selecting the item that follows the current one:

var items = this.navigationBar1.Items;
var index = items.IndexOf(this.navigationBar1.SelectedItem);
if (index > -1 && index < items.Count - 1)
this.navigationBar1.SelectedItem = items[index + 1];

Instance member IndexOfKey(key)​

Returns the index of the first occurrence of the NavigationBarItem with the specified key.

ParameterTypeDescription
keyStringThe name of the NavigationBarItem to find in the collection.

Returns: Int32. The zero-based index of the first occurrence of a NavigationBarItem with the specified key, if found; otherwise, -1.

Returns -1 when key is null or empty.

Example:

Inserting an item after the item named "reports":

var index = this.navigationBar1.Items.IndexOfKey("reports");
this.navigationBar1.Items.Insert(index + 1, "analytics", "Analytics");

Instance member Insert(index, item)​

Inserts an existing NavigationBarItem into the collection at the specified index.

ParameterTypeDescription
indexInt32The zero-based index location where the NavigationBarItem is inserted.
itemNavigationBarItemThe NavigationBarItem to insert in the collection.

Example:

Inserting an item at the top:

this.navigationBar1.Items.Insert(0, new NavigationBarItem { Name = "home", Text = "Home", Icon = "Images/home.svg" });

Instance member Insert(index, text)​

Creates a new NavigationBarItem with the specified text and inserts it into the collection at the specified index.

ParameterTypeDescription
indexInt32The zero-based index location where the NavigationBarItem is inserted.
textStringThe text to display in the NavigationBarItem.

Example:

Inserting an item with only a title at the top:

this.navigationBar1.Items.Insert(0, "Home");

Instance member Insert(index, key, text)​

Creates a new NavigationBarItem with the specified key and text, and inserts it into the collection at the specified index.

ParameterTypeDescription
indexInt32The zero-based index location where the NavigationBarItem is inserted.
keyStringThe name of the NavigationBarItem.
textStringThe text to display on the NavigationBarItem.

Example:

Inserting a named item in the second position:

this.navigationBar1.Items.Insert(1, "news", "News");

Instance member Insert(index, key, text, icon)​

Creates a NavigationBarItem with the specified key, text, and image, and inserts it into the collection at the specified index.

ParameterTypeDescription
indexInt32The zero-based index location where the NavigationBarItem is inserted.
keyStringThe name of the item.
textStringThe text to display on the NavigationBarItem.
iconStringThe Url or name of the icon to display on the NavigationBarItem.

Example:

Inserting an item with an icon in the second position:

this.navigationBar1.Items.Insert(1, "news", "News", "Images/news.svg");

Instance member Remove(item)​

Removes the NavigationBarItem from the collection.

ParameterTypeDescription
itemNavigationBarItemThe NavigationBarItem to remove.

If the removed item is the SelectedItem, the selection is cleared. The item is not disposed.

Throws:

Example:

Removing the selected top-level item:

var item = this.navigationBar1.SelectedItem;
if (item != null && item.Parent == null)
this.navigationBar1.Items.Remove(item);

Instance member RemoveAt(index)​

Removes the NavigationBarItem at the specified index from the collection.

ParameterTypeDescription
indexInt32The zero-based index of the NavigationBarItem to remove.

If the removed item is the SelectedItem, the selection is cleared. The item is not disposed.

Example:

Removing the last item:

var items = this.navigationBar1.Items;
if (items.Count > 0)
items.RemoveAt(items.Count - 1);

Instance member RemoveByKey(key)​

Removes the NavigationBarItem with the specified key from the collection.

ParameterTypeDescription
keyStringThe name of the NavigationBarItem to remove.

Unlike Remove, this method doesn't clear SelectedItem when the removed item is selected.

Example:

Removing an item by name:

this.navigationBar1.Items.RemoveByKey("admin");