I have a context menu in wp7
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu x:Name="onHoldContextMenu">
<toolkit:MenuItem Header="Delete" Tag="{Binding}" Click="DeleteVisitorNote_Click" Visibility="{Binding DeleteContextVisibility, Converter={StaticResource BooleanToVisibilityConverter}}"/>
<toolkit:MenuItem Header="View" Tag="{Binding}" Visibility="{Binding ViewContextVisibility, Converter={StaticResource BooleanToVisibilityConverter}}" Click="ViewVisitorContact_Click"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
I amd changing the visibility for the two items in the view model, it is working fine. My problem is that when I set the visibility to false for both items, I have an empty white line when I open the context menu, and I don’t know how to hide that… I tried:
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu x:Name="onHoldContextMenu" Visibility="{Binding ContextVisibility, Converter={StaticResource BooleanToVisibilityConverter}}">
<toolkit:MenuItem Header="Delete" Tag="{Binding}" Click="DeleteVisitorNote_Click" Visibility="{Binding DeleteContextVisibility, Converter={StaticResource BooleanToVisibilityConverter}}"/>
<toolkit:MenuItem Header="View" Tag="{Binding}" Visibility="{Binding ViewContextVisibility, Converter={StaticResource BooleanToVisibilityConverter}}" Click="ViewVisitorContact_Click"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
But in this case I get a nullrefference exception…
How can I hide the context menu when it is empty?
I found this solution on a different forum.
Setting
e.Handled = truewould block theContextMenufrom receiving theHoldevent. In your view model you would implement some property or method that returns whether to display theContextMenu.