I have a TreeView I'm populating and adding a ContextMenu to each item. The problem is in my ViewModel the TreeView ItemSource is bound to a property on the ViewModel itself. When I attempt to reference some property on the ViewModel again I can't seem to get it to work.
<TreeView Grid.ColumnSpan="1" Grid.Row="1" HorizontalAlignment="Stretch" ItemsSource="{Binding ModelItems}" SelectedTreeItem="{Binding SelectedItem, Mode=TwoWay}" VerticalAlignment="Stretch" Grid.RowSpan="3" Margin="5">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Models}">
<TextBlock Text="{Binding Header, Mode=TwoWay}" ToolTip="{Binding Tooltip, Mode=TwoWay}">
<TextBlock.ContextMenu>
<ContextMenu>
<MenuItem Header="Server" Visibility="{Binding Path=IsServerVisible}">
<MenuItem Header="Add" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Windows:MainWindow}}, Path=ViewModel:ViewModel.AddServerCommand}"/>
<MenuItem Header="Edit" />
<MenuItem Header="Delete" />
</MenuItem>
<MenuItem Header="Config" Visibility="{Binding Path=IsConfigVisible}">
<MenuItem Header="Fetch" />
<MenuItem Header="Edit" />
<MenuItem Header="Save" />
</MenuItem>
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
A previous post on StackOverflow pointed me in the direction of using the RelativeSource to bind correctly to my ViewModel on the MainWindow. However when I run the application the command is not working and the Output window is not generating any binding or xaml errors that I can see.
Basically the Visibility bindings work because those properties exist on the "Models" items. However I want everything to be moved to the ViewModel especially the Command.
Can anyone spot what I've done incorrectly here?