TreeViewItem.Collapsed 事件

定义

IsExpanded 属性从 true 更改为 false 时发生。

public:
 event System::Windows::RoutedEventHandler ^ Collapsed;
public event System.Windows.RoutedEventHandler Collapsed;
member this.Collapsed : System.Windows.RoutedEventHandler 
Public Custom Event Collapsed As RoutedEventHandler 

事件类型

示例

以下示例演示如何将 事件的事件处理程序 Collapsed 分配给 TreeViewItem,以及如何定义事件处理程序。

<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>
private void OnCollapsed(object sender, RoutedEventArgs e)
{
    //Perform actions when the TreeViewItem is collapsed
}
Private Sub OnCollapsed(ByVal sender As Object, ByVal e As RoutedEventArgs)
    'Perform actions when the TreeViewItem is collapsed
End Sub

注解

当 折叠以便隐藏子元素时 TreeViewItem ,会发生此事件。

路由事件信息

标识符字段 CollapsedEvent
路由策略 鼓 泡
委托 RoutedEventHandler

适用于

另请参阅