NavigationBarItemCollection
Namespace: Wisej.Web.Ext.NavigationBar
Assembly: Wisej.Web.Ext.NavigationBar (4.1.0.0)
Contains a collection of NavigationBarItem objects.
- C#
- VB.NET
public class NavigationBarItemCollection : IList, ICollection, IEnumerable, IList<NavigationBarItem>, ICollection<NavigationBarItem>, IEnumerable<NavigationBarItem>
Public Class NavigationBarItemCollection
Inherits IList
Implements ICollection, IEnumerable, IList(Of NavigationBarItem), ICollection(Of NavigationBarItem), IEnumerable(Of NavigationBarItem)
Properties
Count
Int32: Returns the number of items in the collection.
Value: The number of items in the collection.
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:
- ArgumentOutOfRangeException index is less than zero or greater than the highest available index.
- ArgumentNullException value is null.
Example:
Replacing the first item:
this.navigationBar1.Items[0] = new NavigationBarItem { Name = "home", Text = "Home", Icon = "Images/home.svg" };
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
Add(item)
Adds a NavigationBarItem to the collection.
| Parameter | Type | Description |
|---|---|---|
| item | NavigationBarItem | The NavigationBarItem to add. |
Throws:
- ArgumentNullException The specified item is null.
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);
Add(text)
Creates a NavigationBarItem with the specified text, and adds it to the collection.
| Parameter | Type | Description |
|---|---|---|
| text | String | The text to display on the NavigationBarItem. |
Example:
Adding an item with only a title:
this.navigationBar1.Items.Add("Help");
Add(key, text)
Creates a NavigationBarItem with the specified key and text and adds it to the collection.
| Parameter | Type | Description |
|---|---|---|
| key | String | The name of the NavigationBarItem. |
| text | String | The 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";
Add(key, text, icon)
Creates a NavigationBarItem with the specified key, text, and image, and adds it to the collection.
| Parameter | Type | Description |
|---|---|---|
| key | String | The name of the NavigationBarItem. |
| text | String | The text to display on the NavigationBarItem. |
| icon | String | The 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");
AddRange(items)
Adds a set NavigationBarItem objects to the collection.
| Parameter | Type | Description |
|---|---|---|
| items | NavigationBarItem[] | An array of type NavigationBarItem that contains the NavigationBarItem to add. |
Throws:
- ArgumentNullException The value of items is null.
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" }
});
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");
Clear(dispose)
Removes all the NavigationBarItem instances from the collection and optionally disposes them.
| Parameter | Type | Description |
|---|---|---|
| dispose | Boolean | Indicates whether to dispose the NavigationBarItem instances removed from the collection. |
Example:
Removing and disposing all the items:
this.navigationBar1.Items.Clear(true);
Contains(item)
Determines whether a specified NavigationBarItem is in the collection.
| Parameter | Type | Description |
|---|---|---|
| item | NavigationBarItem | The NavigationBarItem to locate in the collection. |
Returns: Boolean. true if the specified NavigationBarItem is in the collection; otherwise, false.
Throws:
- ArgumentNullException The value of item is null.
Example:
Checking whether an item is a top-level item:
if (this.navigationBar1.Items.Contains(this.navigationBar1.SelectedItem))
AlertBox.Show("Top-level item selected.");
ContainsKey(key)
Determines whether the collection contains a NavigationBarItem with the specified key.
| Parameter | Type | Description |
|---|---|---|
| key | String | The 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");
CopyTo(array, index)
Copies the NavigationBarItem instances in the collection to the specified array, starting at the specified index.
| Parameter | Type | Description |
|---|---|---|
| array | NavigationBarItem[] | The one-dimensional array that is the destination of the items copied from the collection. The array must have zero-based indexing. |
| index | Int32 | The zero-based index in the array at which copying begins. |
Throws:
- ArgumentNullException array is null.
- ArgumentOutOfRangeException index is less than zero.
- ArgumentException array is multidimensional or the number of elements in the NavigationBarItemCollection is greater than the available space from index to the end of array .
Example:
Copying the items to an array:
var items = new NavigationBarItem[this.navigationBar1.Items.Count];
this.navigationBar1.Items.CopyTo(items, 0);
IndexOf(item)
Returns the index of the NavigationBarItem in the collection.
| Parameter | Type | Description |
|---|---|---|
| item | NavigationBarItem | The NavigationBarItem to locate in the collection. |
Returns: Int32. The zero-based index of the item; -1 if it cannot be found.
Throws:
- ArgumentNullException The value of item is null.
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];
IndexOfKey(key)
Returns the index of the first occurrence of the NavigationBarItem with the specified key.
| Parameter | Type | Description |
|---|---|---|
| key | String | The 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");
Insert(index, item)
Inserts an existing NavigationBarItem into the collection at the specified index.
| Parameter | Type | Description |
|---|---|---|
| index | Int32 | The zero-based index location where the NavigationBarItem is inserted. |
| item | NavigationBarItem | The 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" });
Insert(index, text)
Creates a new NavigationBarItem with the specified text and inserts it into the collection at the specified index.
| Parameter | Type | Description |
|---|---|---|
| index | Int32 | The zero-based index location where the NavigationBarItem is inserted. |
| text | String | The text to display in the NavigationBarItem. |
Example:
Inserting an item with only a title at the top:
this.navigationBar1.Items.Insert(0, "Home");
Insert(index, key, text)
Creates a new NavigationBarItem with the specified key and text, and inserts it into the collection at the specified index.
| Parameter | Type | Description |
|---|---|---|
| index | Int32 | The zero-based index location where the NavigationBarItem is inserted. |
| key | String | The name of the NavigationBarItem. |
| text | String | The text to display on the NavigationBarItem. |
Example:
Inserting a named item in the second position:
this.navigationBar1.Items.Insert(1, "news", "News");
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.
| Parameter | Type | Description |
|---|---|---|
| index | Int32 | The zero-based index location where the NavigationBarItem is inserted. |
| key | String | The name of the item. |
| text | String | The text to display on the NavigationBarItem. |
| icon | String | The 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");
Remove(item)
Removes the NavigationBarItem from the collection.
| Parameter | Type | Description |
|---|---|---|
| item | NavigationBarItem | The NavigationBarItem to remove. |
If the removed item is the SelectedItem, the selection is cleared. The item is not disposed.
Throws:
- ArgumentNullException The item parameter is null.
Example:
Removing the selected top-level item:
var item = this.navigationBar1.SelectedItem;
if (item != null && item.Parent == null)
this.navigationBar1.Items.Remove(item);
RemoveAt(index)
Removes the NavigationBarItem at the specified index from the collection.
| Parameter | Type | Description |
|---|---|---|
| index | Int32 | The 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);
RemoveByKey(key)
Removes the NavigationBarItem with the specified key from the collection.
| Parameter | Type | Description |
|---|---|---|
| key | String | The 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");