Class TreeViewExtensions
Provides useful extensions to TreeView and TreeViewItem instances.
Inheritance
Inherited Members
Namespace: System.Windows.Controls
Assembly: OpenSilver.dll
Syntax
public static class TreeViewExtensions
Fields
| Improve this Doc View SourceIsCheckedProperty
Identifies the IsChecked dependency property.
Declaration
public static readonly DependencyProperty IsCheckedProperty
Field Value
Type | Description |
---|---|
DependencyProperty |
Methods
| Improve this Doc View SourceClearSelection(TreeView)
Clear the selection of the TreeView.
Declaration
public static void ClearSelection(this TreeView view)
Parameters
Type | Name | Description |
---|---|---|
TreeView | view | The TreeView. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
CollapseAll(TreeView)
Collapse all of the items in a TreeView.
Declaration
public static void CollapseAll(this TreeView view)
Parameters
Type | Name | Description |
---|---|---|
TreeView | view | The TreeView. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
CollapseAllButSelectedPath(TreeView)
Collapse all TreeViewItems except those along the path from the TreeView's SelectedItem to the root of the TreeView.
Declaration
public static void CollapseAllButSelectedPath(this TreeView view)
Parameters
Type | Name | Description |
---|---|---|
TreeView | view | The TreeView. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
ExpandAll(TreeView)
Expand all of the items in a TreeView.
Declaration
public static void ExpandAll(this TreeView view)
Parameters
Type | Name | Description |
---|---|---|
TreeView | view | The TreeView. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
ExpandPath(TreeView, Object[])
Expand the given path of items starting from the TreeView's root.
Declaration
public static void ExpandPath(this TreeView view, params object[] items)
Parameters
Type | Name | Description |
---|---|---|
TreeView | view | The TreeView. |
System.Object[] | items | The sequence of items corresponding to the path to expand. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentNullException |
|
ExpandPath(TreeViewItem)
Expand a path from the TreeViewItem to the root of the TreeView.
Declaration
public static void ExpandPath(this TreeViewItem item)
Parameters
Type | Name | Description |
---|---|---|
TreeViewItem | item | The TreeViewItem. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
ExpandPath<T>(TreeView, IEnumerable<T>)
Expand the given path of items starting from the TreeView's root.
Declaration
public static void ExpandPath<T>(this TreeView view, IEnumerable<T> items)
Parameters
Type | Name | Description |
---|---|---|
TreeView | view | The TreeView. |
System.Collections.Generic.IEnumerable<T> | items | The sequence of items corresponding to the path to expand. |
Type Parameters
Name | Description |
---|---|
T | The type of items provided in |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentNullException |
|
ExpandPath<T>(TreeView, Func<Object, T>, T[])
Expand the given path of items starting from the TreeView's root.
Declaration
public static void ExpandPath<T>(this TreeView view, Func<object, T> comparisonSelector, params T[] items)
Parameters
Type | Name | Description |
---|---|---|
TreeView | view | The TreeView. |
System.Func<System.Object, T> | comparisonSelector | A function that takes a TreeViewItem's item and returns a value to
compare against elements of the given |
T[] | items | The sequence of items corresponding to the path to expand. |
Type Parameters
Name | Description |
---|---|
T | The type of items provided in |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentNullException |
|
ExpandPath<T>(TreeView, Func<Object, T>, IEnumerable<T>)
Expand the given path of items starting from the TreeView's root.
Declaration
public static void ExpandPath<T>(this TreeView view, Func<object, T> comparisonSelector, IEnumerable<T> items)
Parameters
Type | Name | Description |
---|---|---|
TreeView | view | The TreeView. |
System.Func<System.Object, T> | comparisonSelector | A function that takes a TreeViewItem's item and returns a value to
compare against elements of the given |
System.Collections.Generic.IEnumerable<T> | items | The sequence of items corresponding to the path to expand. |
Type Parameters
Name | Description |
---|---|
T | The type of items provided in |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentNullException |
|
ExpandSelectedPath(TreeView)
Expand the path from the SelectedItem to the root of the TreeView.
Declaration
public static void ExpandSelectedPath(this TreeView view)
Parameters
Type | Name | Description |
---|---|---|
TreeView | view | The TreeView. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
ExpandToDepth(TreeView, Int32)
Expand a specified number of layers in a TreeView.
Declaration
public static void ExpandToDepth(this TreeView view, int depth)
Parameters
Type | Name | Description |
---|---|---|
TreeView | view | The TreeView. |
System.Int32 | depth | The number of layers to expand. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
GetCheckedItemsAndContainers(TreeView)
Get the sequence of items and containers with their IsChecked property set to True.
Declaration
public static IEnumerable<KeyValuePair<object, TreeViewItem>> GetCheckedItemsAndContainers(this TreeView view)
Parameters
Type | Name | Description |
---|---|---|
TreeView | view | The TreeView. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.Object, TreeViewItem>> | The sequence of items and containers with their IsChecked property set to True. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
GetCheckedItemsAndContainers(TreeView, Boolean)
Get the sequence of items and containers with their IsChecked property set to True.
Declaration
public static IEnumerable<KeyValuePair<object, TreeViewItem>> GetCheckedItemsAndContainers(this TreeView view, bool includeIndeterminate)
Parameters
Type | Name | Description |
---|---|---|
TreeView | view | The TreeView. |
System.Boolean | includeIndeterminate | A value indicating whether to include TreeViewItems with an indeterminate IsChecked value. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.Object, TreeViewItem>> | The sequence of items and containers with their IsChecked property set to True or also set to null if indeterminate values are included. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
GetContainerFromItem(TreeView, Object)
Get the TreeViewItem already created that is used to represent the given item.
Declaration
public static TreeViewItem GetContainerFromItem(this TreeView view, object item)
Parameters
Type | Name | Description |
---|---|---|
TreeView | view | The TreeView. |
System.Object | item | The item being represented. |
Returns
Type | Description |
---|---|
TreeViewItem | The TreeViewItems that represents the given item, or null if no container was found. |
Remarks
If multiple TreeViewItems represent the same item, the first item found via a breadth-first search will be used.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
GetContainers(TreeView)
Get the TreeViewItem containers of a TreeView.
Declaration
public static IEnumerable<TreeViewItem> GetContainers(this TreeView view)
Parameters
Type | Name | Description |
---|---|---|
TreeView | view | The TreeView. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<TreeViewItem> | The TreeViewItem containers of a TreeView. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
GetContainers(TreeViewItem)
Get the child TreeViewItem containers of a TreeViewItem.
Declaration
public static IEnumerable<TreeViewItem> GetContainers(this TreeViewItem item)
Parameters
Type | Name | Description |
---|---|---|
TreeViewItem | item | The TreeViewItem. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<TreeViewItem> | The child TreeViewItem containers of a TreeViewItem. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
GetContainersFromItem(TreeView, Object)
Get the TreeViewItems already created that are used to represent the given item.
Declaration
public static IEnumerable<TreeViewItem> GetContainersFromItem(this TreeView view, object item)
Parameters
Type | Name | Description |
---|---|---|
TreeView | view | The TreeView. |
System.Object | item | The item being represented. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<TreeViewItem> | A sequence of TreeViewItems that represent the given item, or an empty sequence if none were found. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
GetDepth(TreeViewItem)
Gets the depth of a TreeViewItem in its TreeView (using a zero-based index).
Declaration
public static int GetDepth(this TreeViewItem item)
Parameters
Type | Name | Description |
---|---|---|
TreeViewItem | item | The TreeViewItem. |
Returns
Type | Description |
---|---|
System.Int32 | The depth of a TreeViewItem in its TreeView (using a zero-based index). |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
GetDescendantContainers(TreeView)
Get the TreeViewItem containers of a TreeView.
Declaration
public static IEnumerable<TreeViewItem> GetDescendantContainers(this TreeView view)
Parameters
Type | Name | Description |
---|---|---|
TreeView | view | The TreeView. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<TreeViewItem> | The TreeViewItem containers of a TreeView. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
GetDescendantContainers(TreeViewItem)
Get the descendant TreeViewItem containers of a TreeViewItem.
Declaration
public static IEnumerable<TreeViewItem> GetDescendantContainers(this TreeViewItem item)
Parameters
Type | Name | Description |
---|---|---|
TreeViewItem | item | The TreeViewItem. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<TreeViewItem> | The descendant TreeViewItem containers of a TreeViewItem. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
GetDescendantItemsAndContainers(TreeView)
Get the descendant items and TreeViewItem containers of a TreeView.
Declaration
public static IEnumerable<KeyValuePair<object, TreeViewItem>> GetDescendantItemsAndContainers(this TreeView view)
Parameters
Type | Name | Description |
---|---|---|
TreeView | view | The TreeView. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.Object, TreeViewItem>> | The descendant items and TreeViewItem containers of a TreeView. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
GetDescendantItemsAndContainers(TreeViewItem)
Get the descendant items and TreeViewItem containers of a TreeViewItem.
Declaration
public static IEnumerable<KeyValuePair<object, TreeViewItem>> GetDescendantItemsAndContainers(this TreeViewItem item)
Parameters
Type | Name | Description |
---|---|---|
TreeViewItem | item | The TreeViewItem. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.Object, TreeViewItem>> | The descendant items and TreeViewItem containers of a TreeViewItem. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
GetIsChecked(TreeViewItem)
Gets the value of the IsChecked attached property for a specified TreeViewItem.
Declaration
public static bool? GetIsChecked(this TreeViewItem element)
Parameters
Type | Name | Description |
---|---|---|
TreeViewItem | element | The TreeViewItem from which the property value is read. |
Returns
Type | Description |
---|---|
System.Nullable<System.Boolean> | The IsChecked property value for the TreeViewItem. |
GetIsLeaf(TreeViewItem)
Gets a value indicating whether the TreeViewItem is a leaf in its TreeView.
Declaration
public static bool GetIsLeaf(this TreeViewItem item)
Parameters
Type | Name | Description |
---|---|---|
TreeViewItem | item | The TreeViewItem. |
Returns
Type | Description |
---|---|
System.Boolean | A value indicating whether the TreeViewItem is a leaf in its TreeView. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
GetIsRoot(TreeViewItem)
Gets a value indicating whether the TreeViewItem is a root of its TreeView.
Declaration
public static bool GetIsRoot(this TreeViewItem item)
Parameters
Type | Name | Description |
---|---|---|
TreeViewItem | item | The TreeViewItem. |
Returns
Type | Description |
---|---|
System.Boolean | A value indicating whether the TreeViewItem is a root of its TreeView. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
GetItem(TreeViewItem)
Get the item wrapped by this container.
Declaration
public static object GetItem(this TreeViewItem item)
Parameters
Type | Name | Description |
---|---|---|
TreeViewItem | item | The TreeViewItem. |
Returns
Type | Description |
---|---|
System.Object | The item wrapped by the container, or null if not found. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
GetItemsAndContainers(TreeView)
Get the items and TreeViewItem containers of a TreeView.
Declaration
public static IEnumerable<KeyValuePair<object, TreeViewItem>> GetItemsAndContainers(this TreeView view)
Parameters
Type | Name | Description |
---|---|---|
TreeView | view | The TreeView. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.Object, TreeViewItem>> | The items and TreeViewItem containers of a TreeView. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
GetItemsAndContainers(TreeViewItem)
Get the items and TreeViewItem containers of a TreeViewItem.
Declaration
public static IEnumerable<KeyValuePair<object, TreeViewItem>> GetItemsAndContainers(this TreeViewItem item)
Parameters
Type | Name | Description |
---|---|---|
TreeViewItem | item | The TreeViewItem. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.Object, TreeViewItem>> | The items and TreeViewItem containers of a TreeViewItem. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
GetParentItem(TreeView, Object)
Get the item of the parent container for a specified
item
.
Declaration
public static object GetParentItem(this TreeView view, object item)
Parameters
Type | Name | Description |
---|---|---|
TreeView | view | The TreeView containing the |
System.Object | item | The child item. |
Returns
Type | Description |
---|---|
System.Object | The item of the parent container for the specified
|
GetParentTreeView(TreeViewItem)
Get the parent TreeView of a TreeViewItem.
Declaration
public static TreeView GetParentTreeView(this TreeViewItem item)
Parameters
Type | Name | Description |
---|---|---|
TreeViewItem | item | The TreeViewItem. |
Returns
Type | Description |
---|---|
TreeView | The parent TreeView if found, otherwise null. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
GetParentTreeViewItem(TreeViewItem)
Get the parent TreeViewItem of a TreeViewItem.
Declaration
public static TreeViewItem GetParentTreeViewItem(this TreeViewItem item)
Parameters
Type | Name | Description |
---|---|---|
TreeViewItem | item | The TreeViewItem. |
Returns
Type | Description |
---|---|
TreeViewItem | The parent TreeViewItem if found, otherwise null. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
GetPath(TreeViewItem)
Gets a path of items and TreeViewItem containers from the TreeViewItem to the root of the TreeView.
Declaration
public static IEnumerable<KeyValuePair<object, TreeViewItem>> GetPath(this TreeViewItem item)
Parameters
Type | Name | Description |
---|---|---|
TreeViewItem | item | The TreeViewItem. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.Object, TreeViewItem>> | A path of items and TreeViewItem containers from the TreeViewItem to the root of the TreeView. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
GetSelectedContainer(TreeView)
Get the selected TreeViewItem in a TreeView.
Declaration
public static TreeViewItem GetSelectedContainer(this TreeView view)
Parameters
Type | Name | Description |
---|---|---|
TreeView | view | The TreeView. |
Returns
Type | Description |
---|---|
TreeViewItem | The selected TreeViewItem, or null if no selected item found. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
GetSelectedPath(TreeView)
Gets the path to the TreeView's selected item.
Declaration
public static IEnumerable<KeyValuePair<object, TreeViewItem>> GetSelectedPath(this TreeView view)
Parameters
Type | Name | Description |
---|---|---|
TreeView | view | The TreeView. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.Object, TreeViewItem>> | The path to the TreeView's selected item. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
GetSiblingItemsAndContainers(TreeViewItem)
Get the sibling items and containers of the item.
Declaration
public static IEnumerable<KeyValuePair<object, TreeViewItem>> GetSiblingItemsAndContainers(this TreeViewItem item)
Parameters
Type | Name | Description |
---|---|---|
TreeViewItem | item | The TreeViewItem. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.Object, TreeViewItem>> | The sibling items and containers of the item. |
SelectItem(TreeView, Object)
Select an item in the TreeView.
Declaration
public static bool SelectItem(this TreeView view, object item)
Parameters
Type | Name | Description |
---|---|---|
TreeView | view | The TreeView. |
System.Object | item | The item to select. |
Returns
Type | Description |
---|---|
System.Boolean | A value indicating whether the item was successfully set as the TreeView's SelectedItem. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
SetIsChecked(TreeViewItem, Nullable<Boolean>)
Sets the value of the IsChecked attached property to a specified TreeViewItem.
Declaration
public static void SetIsChecked(this TreeViewItem element, bool? value)
Parameters
Type | Name | Description |
---|---|---|
TreeViewItem | element | The TreeViewItem to which the attached property is written. |
System.Nullable<System.Boolean> | value | The needed IsChecked value. |
SetSelectedContainer(TreeView, TreeViewItem)
Sets the selected TreeViewItem of a TreeView.
Declaration
public static void SetSelectedContainer(this TreeView view, TreeViewItem item)
Parameters
Type | Name | Description |
---|---|---|
TreeView | view | The TreeView. |
TreeViewItem | item | The TreeViewItem to select. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|