I currently have a UserControl that uses the MVVM model.
This control has a TreeView that displays some elements. I added a HierarchicalDataTemplate for this TreeView and in this template is ContextMenu for the elements.
In the ViewModel, which is the DataContext of the control (named RestoresTreeViewControl), is the command I want to associate with one of the menu items. However, what I did does not seem to work. I get the usual can not find the source for the link binding.
Here is a bit of code for the data file that tried to bind EditDatabaseCommand with one of the menu items.
<HierarchicalDataTemplate DataType="{x:Type model:Database}" > <StackPanel> <TextBlock Text="{Binding Name}" > <TextBlock.ContextMenu> <ContextMenu> <MenuItem Header="Edit" Command="{Binding ElementName=RestoresTreeViewControl, Path=DataContext.EditDatabaseCommand}" /> <MenuItem Header="Delete"/> <Separator/> <MenuItem Header="Test Connection"/> </ContextMenu> </TextBlock.ContextMenu> </TextBlock> </StackPanel> </HierarchicalDataTemplate>
Here is the ViewModel section where the command is located.
public ICommand EditDatabaseCommand { get; private set; }
source share