共用方式為


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

適用於

另請參閱