.NET Framework Class Library
TreeViewItem..::.IsExpanded Property

Gets or sets whether the nested items in a TreeViewItem are expanded or collapsed. This is a dependency property.

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
Syntax

Visual Basic (Declaration)
Public Property IsExpanded As Boolean
Visual Basic (Usage)
Dim instance As TreeViewItem
Dim value As Boolean

value = instance.IsExpanded

instance.IsExpanded = value
C#
public bool IsExpanded { get; set; }
Visual C++
public:
property bool IsExpanded {
    bool get ();
    void set (bool value);
}
JScript
public function get IsExpanded () : boolean
public function set IsExpanded (value : boolean)
XAML Attribute Usage
<object IsExpanded="bool" .../>

Property Value

Type: System..::.Boolean
true if the nested items of a TreeViewItem are visible; otherwise, false. The default is false.
Dependency Property Information

Identifier field

IsExpandedProperty

Metadata properties set to true

None

Remarks

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.

Examples

The following example shows how to set the IsExpanded property.

XAML
<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>
C#
Employee1Data.IsExpanded = true;
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0
See Also

Reference

Tags :


Page view tracker