Скрыть последних авторов
Alexandr Fokin 1.4 1 | |TreeView
Alexandr Fokin 1.2 2 | |(((
Alexandr Fokin 1.4 3 | |Обработка событий: Expanded, DoubleClick
Alexandr Fokin 1.3 4 |xaml|{{code language="xml"}}<TreeView
Alexandr Fokin 1.2 5 Name="ElementsTreeView"
6
7 ItemsSource="{Binding Path=Root}"
8 TreeViewItem.Expanded="ElementsTreeView_Expanded"
9 TreeViewItem.MouseDoubleClick="ElementsTreeView_MouseDoubleClick">
10
11 <TreeView.ItemTemplate>
12 <HierarchicalDataTemplate ItemsSource="{Binding Path=Childs}">
13 <StackPanel Orientation="Horizontal">
14
15 <!--item template-->
16
17 </StackPanel>
18 </HierarchicalDataTemplate>
19 </TreeView.ItemTemplate>
20
21 </TreeView>{{/code}}
Alexandr Fokin 1.3 22 |code|{{code language="c#"}}private async void ElementsTreeView_Expanded(object sender, RoutedEventArgs e)
Alexandr Fokin 1.2 23 {
24 var item = (TreeViewItem)e.OriginalSource;
Alexandr Fokin 1.5 25 var node = item.DataContext as IViewModelItem;
Alexandr Fokin 1.2 26
27 //...
28 }
29
30 private async void ElementsTreeView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
31 {
Alexandr Fokin 1.5 32 IViewModelItem node = null;
Alexandr Fokin 1.2 33
34 if (sender is TreeView treeView)
35 {
Alexandr Fokin 1.5 36 if (treeView.SelectedItem is IViewModelItem viewNode)
Alexandr Fokin 1.2 37 {
38 node = viewNode;
39 }
40 }
Alexandr Fokin 1.3 41
42 //...
Alexandr Fokin 1.2 43 }{{/code}}
Alexandr Fokin 1.3 44 | |
Alexandr Fokin 1.2 45
46
47 )))
48 | |