Introduction
Projects often use the TreeView to organize some hierarchical data, and this section summarizes the projects using the common questions in the TreeView.
DataBinding Data Binding
DataTemplate Custom
<hierarchicaldatatemplateDataType="{x:type Viewmodels:fieldviewmodel}"ItemsSource="{Binding Subviewmodels}"> <StackPanelOrientation= "Horizontal"> <TextBlockText= "F:"Style="{StaticResource Icontextstyle}"Background= "Lightcoral"/> <TextBlockText="{Binding CurrentEntity.Value.Name}"Focusable= "True"> <Textblock.contextmenu> <ContextMenu> <MenuItemHeader= "New Well"Command="{Binding AddCommand}"CommandParameter="{Binding Path=currententity.value}" /> <MenuItemHeader= "Delete"Command="{Binding DeleteCommand}"CommandParameter="{Binding Path=currententity.value}" /> </ContextMenu> </Textblock.contextmenu> </TextBlock> </StackPanel> </hierarchicaldatatemplate>
Style customization
Events Order
Selecteditemchanged occurs in the TreeView to the new SelectedItem focus (set focus on its new selected item).
Bottom line: Selecteditemchanged–>set Foucs on the new selected item.
From: https://social.msdn.microsoft.com/Forums/en-US/e41ec0e1-f63e-40a3-bfea-1d61d0cfcf1e/ Set-focus-on-textbox-after-click-on-treeviewselecteditemchanged?forum=wpf&prof=required
[Common Considerations for WPF series]-treeview