> For the complete documentation index, see [llms.txt](https://docs.devolutions.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.devolutions.net/powershell-universal/es/comandos-de-powershell/new-udtreeview.md).

# New-UDTreeView

New-UDTreeView crea un árbol jerárquico de elementos New-UDTreeNode expandibles en PowerShell Universal para explorar estructuras de datos anidadas.

### Sinopsis

Crea una nueva vista de árbol.

### Sintaxis

```powershell
New-UDTreeView [[-Id] <String>] [-Node] <ScriptBlock> [[-OnNodeClicked] <Endpoint>] [[-Style] <Hashtable>] [[-ClassName] <String>] [-Expanded] [-PreventCollapse] [<CommonParameters>]
```

### Descripción

Crea una nueva vista de árbol.

### Parámetros

#### -Id

El ID del componente. De forma predeterminada es un GUID aleatorio.

```
Required?                    false
Position?                    1
Default value                [Guid]::NewGuid()
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Node

Una colección de nodos raíz que se mostrarán en la vista de árbol.

```
Required?                    true
Position?                    2
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -OnNodeClicked

Un bloque de script que se llama cuando se hace clic en un nodo. $EventData contendrá el nodo en el que se hizo clic.

```
Required?                    false
Position?                    3
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Style

Un conjunto de estilos CSS que se aplicarán a la vista de árbol.

```
Required?                    false
Position?                    4
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -ClassName

Un className de CSS que se aplicará a la vista de árbol.

```
Required?                    false
Position?                    5
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Expanded

Si la vista de árbol debe estar expandida de forma predeterminada.

```
Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -PreventCollapse

Impide que la vista de árbol se contraiga cuando se hace clic en un nodo. Asume -Expanded.

```
Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### Parámetros comunes

Este cmdlet admite los parámetros comunes: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, PipelineVariable y OutVariable. Para obtener más información, consulte [about\_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).

### Salidas

### Ejemplos

#### Ejemplo 1: vista de árbol

```powershell
New-UDTreeView -Node {
    New-UDTreeNode -Name "Root Node" -Id "root1" -Children {
        New-UDTreeNode -Name "Child Node" -Id "child1" -Children {
            New-UDTreeNode -Name "Grandchild Node" -Id "grandchild1" -Leaf
        }
        New-UDTreeNode -Name "Child Node 2" -Id "child2" -Children {
            New-UDTreeNode -Name "Grandchild Node 2" -Id "grandchild2" -Leaf
        }
    }
} -Id "treeview1"
```

Un componente básico de vista de árbol.

#### Ejemplo 2: OnNodeClicked

```powershell
New-UDTreeView -Node {
    New-UDTreeNode -Name "Root Node" -Id "root2" -Children {
        New-UDTreeNode -Name "Child Node" -Id "child3" -Children {
            New-UDTreeNode -Name "Grandchild Node" -Id "grandchild3" -Leaf
        }
        New-UDTreeNode -Name "Child Node 2" -Id "child4" -Children {
            New-UDTreeNode -Name "Grandchild Node 2" -Id "grandchild4"
        }
    }
} -Id "treeview2" -OnNodeClicked {
    Show-UDToast -Message "You clicked $($EventData.Id)"
}
```

Una vista de árbol con un bloque de script OnNodeClicked que muestra un aviso cuando se hace clic en un nodo.

#### Ejemplo 3: Expanded

```powershell
New-UDTreeView -Node {
    New-UDTreeNode -Name "Root Node" -Id "root3" -Children {
        New-UDTreeNode -Name "Child Node" -Id "child5" -Children {
            New-UDTreeNode -Name "Grandchild Node" -Id "grandchild5"  -Leaf
        }
        New-UDTreeNode -Name "Child Node 2" -Id "child6" -Children {
            New-UDTreeNode -Name "Grandchild Node 2" -Id "grandchild6"  -Leaf
        }
    }
} -Id "treeview3" -Expanded
```

Una vista de árbol que está expandida de forma predeterminada.

#### Ejemplo 4: OnNodeClicked

```powershell
New-UDTreeView -Node {
    New-UDTreeNode -Name "Root Node" -Id "root4"
} -Id "treeview4" -OnNodeClicked {
    New-UDTreeNode -Name "Child Node"
}
```

Una vista de árbol con un bloque de script OnNodeClicked que añade un nodo hijo cuando se hace clic en un nodo.

#### Ejemplo 5: iconos

```powershell
New-UDTreeView -Node {
    New-UDTreeNode -Name "Root Node" -Id "root5" -Children {
        New-UDTreeNode -Name "Child Node" -Id "child7" -Children {
            New-UDTreeNode -Name "Grandchild Node" -Id "grandchild7" -Leaf -Icon (New-UDIcon -Icon "File")
        } -Icon (New-UDIcon -Icon "Folder") -ExpandedIcon (New-UDIcon -Icon "FolderOpen")
        New-UDTreeNode -Name "Child Node 2" -Id "child8" -Children {
            New-UDTreeNode -Name "Grandchild Node 2" -Id "grandchild8" -Leaf -Icon (New-UDIcon -Icon "File")
        } -Icon (New-UDIcon -Icon "Folder") -ExpandedIcon (New-UDIcon -Icon "FolderOpen")
    }
} -Id "treeview5" -Expanded
```

Una vista de árbol con iconos para los nodos.

#### Ejemplo 6: PreventCollapse

```powershell
New-UDTreeView -Node {
    New-UDTreeNode -Name "Root Node" -Id "root6" -Children {
        New-UDTreeNode -Name "Child Node" -Id "child9" -Children {
            New-UDTreeNode -Name "Grandchild Node" -Id "grandchild9"  -Leaf
        }
        New-UDTreeNode -Name "Child Node 2" -Id "child10" -Children {
            New-UDTreeNode -Name "Grandchild Node 2" -Id "grandchild10"  -Leaf
        }
    }
} -Id "treeview3" -Expanded -PreventCollapse
```

Una vista de árbol que está expandida de forma predeterminada e impide contraerse cuando se hace clic en un nodo.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.devolutions.net/powershell-universal/es/comandos-de-powershell/new-udtreeview.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
