✅ WPF - Accessing a TreeViewItem's root UserControl DataContext for a Command
I am trying to execute a Command which exists in the ViewModel bound to the root parent UserControl of a child TreeViewItem. This is from a ContextMenu bound to root TreeViewItems. The TreeView code:
Key code:
Broader context:
https://paste.mod.gg/khruicdqkfhy/1
MainWindowViewModel
is the DataContext of MainWindow, within which the Command I'm targeting exists. I've tried various permutations of RelativeSource for Binding, as despite xaml intellisense suggesting the binding is right by offering the command as an option, it doesn't fire on selecting the relevant ContextMenuItem.
Any ideas?BlazeBin - khruicdqkfhy
A tool for sharing your source code with the world!
1 Reply
Stack Overflow
WPF ContextMenu woes: How do I set the DataContext of the ContextMenu?
I am having some trouble figuring out how to set the correct DataContext on a ContextMenu.
I have a collection of view models who are the source of an ItemsControl. Each view model has a collect...