Tecman
Tecman

Reputation: 3009

Disabling context menu item dynamically in a WP app

I'm using the ContextMenu class from the Microsoft.Phone.Controls.Toolkit library to implement a custom context menu for a data-bound ListBox. The simplified part of XAML looks like this:

<toolkit:ContextMenuService.ContextMenu>
    <toolkit:ContextMenu IsZoomEnabled="True" x:Name="contextMenuItems">
        <toolkit:MenuItem x:Name="contextMenuItemPinToStart" Header="pint to start"/>
        <toolkit:MenuItem Header="rename"/>
        <toolkit:MenuItem Header="delete"/>
    </toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>

I need to disable the 'pin to start' item dynamically when this context menu is about to be opened. There are some problems with implementing this:

  1. We do not have a corresponding OnShow event.
  2. I cannot retrieve the list item the context menu was shown for (most likely, this point depends on the answer to this previous question).
  3. I cannot access the context menu item by its name (contextMenuItemPinToStart) to set its IsEnabled property.

Can anybody show me a suitable solution?

Upvotes: 0

Views: 141

Answers (0)

Related Questions