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:
<Grid x:Name="GistBrowserGRD" Grid.Row="0" Margin="2">
<Grid.Resources>
<HierarchicalDataTemplate DataType="{x:Type viewmodels:GistViewModel}" ItemsSource="{Binding Path=GistFiles}">
<StackPanel Orientation="Horizontal">
<TextBlock VerticalAlignment="Center" Margin="2,0,2,0"
Text="{Binding GistFiles, Converter={StaticResource GistFilesToFirstFilenameConverter}}"></TextBlock>
<StackPanel.ContextMenu>
<ContextMenu Style="{StaticResource ContextMenu}">
<MenuItem Header="Delete Gist" Background="{DynamicResource {x:Static vsshell:VsBrushes.WindowKey}}"
Style="{StaticResource MenuItem}"
Command="{Binding
RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type viewmodels:MainWindowViewModel}},
Path=DataContext.DeleteGistCMD}">
<MenuItem.Icon>
<imaging:CrispImage Moniker="{x:Static catalog:KnownMonikers.DeleteListItem}"/>
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</StackPanel.ContextMenu>
</StackPanel>
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type viewmodels:GistFileViewModel}">
<StackPanel Orientation="Horizontal">
<imaging:CrispImage VerticalAlignment="Center" Width="16" Height="16" Margin="0,0,4,0"
Moniker="{x:Static catalog:KnownMonikers.Document}" />
<TextBlock VerticalAlignment="Center" Margin="2,0,2,0" Text="{Binding Filename}"></TextBlock>
</StackPanel>
</DataTemplate>
</Grid.Resources>
<TreeView x:Name="GistsTV" ItemsSource="{Binding Gists}" BorderThickness="0" Background="Transparent">
<TreeView.Resources>
<!-- Style the inactive selection the same as active -->
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}"
Color="#808080" Opacity="0.4"/>
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}"
Color="{DynamicResource {x:Static SystemColors.HighlightTextColorKey}}"/>
</TreeView.Resources>
<i:Interaction.Behaviors>
<behaviours:BindableSelectedItemBehavior SelectedItem="{Binding SelectedGistVmItem, Mode=TwoWay}" />
</i:Interaction.Behaviors>
</TreeView>
</Grid>
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 at right by offering the command as an option, it doesn’t fire on selecting the relevant ContextMenuItem.
Any ideas?