Контролы - TreeView 

Page / - Изменено Alexandr Fokin в 2024/09/15 12:07 

TreeView 
Изменено Alexandr Fokin
в 2024/09/15 12:07

Оглавление

 	TreeView	
 	 	Обработка событий: Expanded, DoubleClick	
xaml	<TreeView
Name="ElementsTreeView"

ItemsSource="{Binding Path=Root}"
TreeViewItem.Expanded="ElementsTreeView_Expanded"
TreeViewItem.MouseDoubleClick="ElementsTreeView_MouseDoubleClick">

<TreeView.ItemTemplate>
 <HierarchicalDataTemplate ItemsSource="{Binding Path=Childs}">
  <StackPanel Orientation="Horizontal">

   <!--item template-->
   
  </StackPanel>
 </HierarchicalDataTemplate>
</TreeView.ItemTemplate>
           
</TreeView>	
code	private async void ElementsTreeView_Expanded(object sender, RoutedEventArgs e)
{
   var item = (TreeViewItem)e.OriginalSource;
   var node = item.DataContext as IViewModelItem;

//...
}

private async void ElementsTreeView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    IViewModelItem node = null;

   if (sender is TreeView treeView)
    {
       if (treeView.SelectedItem is IViewModelItem viewNode)
        {
            node = viewNode;
        }
    } 

 //...
}