I assume this is the context menu that you come across using data binding.
The toggler is not in the logical tree of the context menu, so he cannot find the togglebotton button using ElementName, see http://blogs.msdn.com/b/mikehillberg/archive/2008/05/23/of-logical-and -visual-trees-in-wpf.aspx
This is why you get an error for this binding in your output window in VS:
Error System.Windows.Data: 4: Cannot find source for binding with reference 'ElementName = toggleButton'. BindingExpression: Path = IsChecked; DataItem = NULL; target element 'MenuItem' (Name = 'menuItemBlock'); target is is IsChecked - (type 'Boolean')
To fix, find the toggle button using FindAncestor:
<MenuItem Header="Block" IsCheckable="True" IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ContextMenu}, Path=PlacementTarget.IsChecked}" />
Wallstreet programmer
source share