0

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?

TecMan
  • 2,743
  • 2
  • 30
  • 64
  • Can you databind the IsEnabled property? I mean creating a public bool property in your viewmodel and bind to that property (...`IsEnabled="{Binding IsEnabled}"`...) – xmashallax Sep 04 '14 at 12:42
  • You can try another approach by adding only the "rename" and "delete" items in the XAML and dynamically add the "pin to start", if you can access the `contextMenuItems` – godidier Jun 17 '15 at 10:30

0 Answers0