How to bind to the DataContext of a HierarchicalDataTemplate from its ItemTemplate XAML?
问题 In my WPF TreeView, I have defined a HierarchicalDataTemplate . In its ItemTemplate , there is a button whose Command I need to bind to the parent ViewModel, this is the DataContext of the parent HierarchicalDataTemplate or, in other words, the ViewModel which holds the collection SubItems in the example below. The ItemTemplate s own DataContext - the SubItem - is to be used as the CommandParameter . <TreeView ItemsSource="{Binding Items}"> <TreeView.ItemTemplate> <HierarchicalDataTemplate