共用方式為


TreeView.SelectedItemChanged 事件

定義

發生於 SelectedItem 變更時。

public:
 event System::Windows::RoutedPropertyChangedEventHandler<System::Object ^> ^ SelectedItemChanged;
public event System.Windows.RoutedPropertyChangedEventHandler<object> SelectedItemChanged;
member this.SelectedItemChanged : System.Windows.RoutedPropertyChangedEventHandler<obj> 
Public Custom Event SelectedItemChanged As RoutedPropertyChangedEventHandler(Of Object) 

事件類型

範例

下列範例示範如何指定 事件的事件處理常式 SelectedItemChanged

<TreeView SelectedItemChanged="SelectionChanged">
  <TreeViewItem Header="Employee1" IsSelected="True">
    <TreeViewItem Header="Jesper"/>
    <TreeViewItem Header="Aaberg"/>
    <TreeViewItem Header="12345"/>
  </TreeViewItem>
  <TreeViewItem Header="Employee2">
    <TreeViewItem Header="Dominik"/>
    <TreeViewItem Header="Paiha"/>
    <TreeViewItem Header="98765"/>
  </TreeViewItem>
</TreeView>

下列範例示範如何定義事件處理常式。

private void SelectionChanged(object sender, RoutedPropertyChangedEventArgs<Object> e)
{
    //Perform actions when SelectedItem changes
    MessageBox.Show(((TreeViewItem) e.NewValue).Header.ToString());
}
Private Sub SelectionChanged(ByVal sender As Object, ByVal e As RoutedPropertyChangedEventArgs(Of Object))
    'Perform actions when SelectedItem changes
    MessageBox.Show((CType(e.NewValue, TreeViewItem)).Header.ToString())
End Sub

備註

路由事件資訊

識別碼欄位 SelectedItemChangedEvent
路由策略 鼓 泡
代理人 RoutedPropertyChangedEventHandler<T>

XAML Attribute Usage

<object SelectedItemChanged="RoutedPropertyChangedEventHandler"/>  

適用於