Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

TreeViewItem.IsExpanded Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets or sets whether the nested items in a TreeViewItem are expanded or collapsed.

Namespace:   System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)

public bool IsExpanded { get; set; }

Property Value

Type: System.Boolean

true if the nested items of a TreeViewItem are visible; otherwise, false. The default is false.

The appearance of the button that expands and collapses the TreeViewItem changes when the TreeViewItem is expanded or collapsed. When the IsExpanded property value changes from true to false, the Collapsed event occurs. Similarly, the Expanded event occurs when the IsExpanded property value changes from false to true.

Identifier field

IsExpandedProperty

Metadata properties set to true

None

The following example shows how to set the IsExpanded property.

<TreeViewItem Header="Employee1"
              Name="Employee1Data" 
              IsExpanded="True" 
              Collapsed="OnCollapsed" 
              Expanded="OnExpanded">
  <TreeViewItem Header="Work Days" 
                Name="EmployeeWorkDays"
                IsSelected="True">
    <TreeViewItem Header="Tuesday" />
    <TreeViewItem Header="Friday"/>
  </TreeViewItem>
</TreeViewItem>
<TreeViewItem Header="Employee2" 
              Name="Employee2Data">
  <TreeViewItem Header="Work Days" 
                Name="emp2WorkDays" 
                Selected="GetSchedule"
                Unselected="SetSchedule">
    <TreeViewItem Header="Monday" />
    <TreeViewItem Header="Wednesday"/>
  </TreeViewItem>
</TreeViewItem>
Employee1Data.IsExpanded = true;

.NET Framework
Available since 3.0
Silverlight
Available since 3.0
Return to top
Show:
© 2017 Microsoft