This is the style for my ContextMenu:
<Style x:Key="DIOStyle" TargetType="ContentControl">
<Setter Property="Tag" Value="{Binding Content,RelativeSource={RelativeSource Mode=Self}}"/>
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu>
<MenuItem Style="{StaticResource DeleteMenuItemStyle}"/>
<!--<MenuItem Header="Normality">
<MenuItem Style="{StaticResource NcMenuItemStyle}"/>
<MenuItem Style="{StaticResource NaMenuItemStyle}"/>
</MenuItem>-->
<MenuItem Style="{StaticResource BothContactsMenuItemStyle}"/>
</ContextMenu>
</Setter.Value>
</Setter>
...
and this is the style for my MenuItem:
<Style x:Key="BothContactsMenuItemStyle" TargetType="MenuItem">
<Setter Property="Header" Value="Both Contacts"/>
<Setter Property="Command" Value="{Binding PlacementTarget.Tag.BothNaNcChangeCommand,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ContextMenu}}"/>
<Setter Property="Icon">
<Setter.Value>
<Image Style="{StaticResource Tick16Style}" Visibility="{Binding PlacementTarget.Tag.BothNaNc, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ContextMenu}, Converter={StaticResource BoolToVis}}"/>
</Setter.Value>
</Setter>
</Style>
Command binding is working, instead icon visibility binding give me this error:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ContextMenu', AncestorLevel='1''. BindingExpression:Path=PlacementTarget.Tag.BothNaNc; DataItem=null; target element is 'Image' (Name=''); target property is 'Visibility' (type 'Visibility')
Why? Please note, this is working:
<MenuItem Header="TEST" Visibility="{Binding PlacementTarget.Tag.BothNaNc, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ContextMenu}, Converter={StaticResource BoolToVis}}"/>