My user control context menu visibility can't bind a dependency property. Any idea?
Here is my WPF code
<UserControl.ContextMenu>
<ContextMenu Visibility="{Binding ElementName=wellControl, Path=IsInCompactMode, Converter={StaticResource BooleanToVisibilityConverter}}">
<MenuItem Command="local:GCommands.Edit" />
<MenuItem Command="local:GCommands.Delete" />
<MenuItem Command="local:GCommands.ExportFcsFiles" />
<MenuItem Command="local:GCommands.BatchExportStatistics" />
<Separator/>
<MenuItem Command="local:GCommands.SaveAs" Header="Save As..." />
</ContextMenu>
</UserControl.ContextMenu>
If I set Visibility="Hidden" it will work for me. like this:
<ContextMenu Visibility="Hidden"/>
If use this it won't work
<ContextMenu Visibility="{Binding ElementName=wellControl, Path=IsInCompactMode, Converter={StaticResource BooleanToVisibilityConverter}}">
I'm pretty sure Visibility="{Binding ElementName=wellControl, Path=IsInCompactMode, Converter={StaticResource BooleanToVisibilityConverter}}" has not problem, cuz it works for others.
here is my dependency property
public bool IsInCompactMode
{
get {return (bool)GetValue(IsInCompactModeProperty); }
set {SetValue(IsInCompactModeProperty, value); }
}
public static readonly DependencyProperty IsInCompactModeProperty =
DependencyProperty.Register("IsInCompactMode", typeof(bool), typeof(WellControl), new PropertyMetadata(false));
I tried this way, it seems it still doesn't work, this is really weird!!!
<ContextMenu x:Name="menu" IsOpen="{Binding ElementName=wellControl, Path=IsInCompactMode}">
I'm really confuse about it, what's wrong? "Binding ElementName=wellControl, Path=IsInCompactMode" works for other part of the user control, just doesn't work for the weird context menu? it doesn't make sence