Visibility="{Binding Path=Visibility, ElementName=btnUndo}"/>
I am trying to bind a menuitems visibility to another controls visibility (btnUndo).
That controls visibility is bound to a trigger
<Style x:Key="undoStyle">
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedItem.isEdited, ElementName=lvBatches}" Value="True">
<Setter Property="FrameworkElement.Visibility" Value="Visible"/>
</DataTrigger>
<DataTrigger Binding="{Binding SelectedItem.isEdited, ElementName=lvBatches}" Value="False">
<Setter Property="FrameworkElement.Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
I tried binding the MenuItem to the same trigger, but that didn’t work either.
Any suggestions?
ContextMenusexist in the Adorner Layer, which is not the same Visual Tree as the UI layer.I know you can bind something like the following in a
MenuItem, which will return theControltheContextMenuis attached to, and from there you might be able to find the data you’re looking for.For example, you could create a Converter which traverses up the
VisualTreefrom the specified control until it finds the object it’s looking for, or you could bind to the DataContext and look for a specific value within your ViewModel.