I have a scenario where I have a WPF TreeView control that has an HierarchicalDataTemplate for its items. Now inside the HierarchicalDataTemplate, I have a Label and the Label has a ContextMenu with a menuitem for Delete. The Delete menuitem is binded with a Command called DeleteCommand which is a part of the class that has been set as the DataType of the HierarchicalDataTemplate.
Now, I want to pass the TreeView control in the CommandParameters of the ContextMenu's Delete menuitem's DeleteCommand so that I can handle the selection of the TreeViewItems on the deletion of the currently selected item.
But if I bind the CommandParameters as the {Binding ElementName=TreeViewName} or whatever for that matter, it is always null unless the binded element is a property in the DataContext.
Can anyone help me with a solution because I think, I have tried all the possible things such as RelativeSource and AncestorType etc but its always null. To me, it looks like either a limitation or a bug in the framework.