1

So I followed the solution here: ContextMenu on tap instead of tap and hold to pop open a ContextMenu on "tap" instead of "hold" which ends up working, kind of...

As another user mentioned as a reply to that answer, the ContextMenu actually opens up at the top of the screen instead of where it was "tapped" from.

Any ideas why this is happening and any suggestions to fix it?

Resources XAML:

<DataTemplate x:Key="InventoryListDataTemplate">
    <StackPanel Orientation="Vertical" Margin="0,0,0,17" Tap="OpenContextMenu">
    <toolkit:ContextMenuService.ContextMenu>
        <toolkit:ContextMenu x:Name="WeaponContextMenu">
            <toolkit:MenuItem Header="Equip" />
            <toolkit:MenuItem Header="Discard" />
        </toolkit:ContextMenu>
    </toolkit:ContextMenuService.ContextMenu>
    </StackPanel>
</DataTemplate>

Content XAML:

<Grid>
    <ListBox ItemTemplate="{StaticResource InventoryListDataTemplate}" Name="InventoryAllListBox" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</Grid>

Code:

private void OpenContextMenu(object sender, EventArgs e)
{
    ContextMenu contextMenu = ContextMenuService.GetContextMenu(sender as StackPanel);

    if (contextMenu.Parent == null)
    {
        contextMenu.IsOpen = true;
    }
}
Community
  • 1
  • 1
Microsis
  • 279
  • 1
  • 2
  • 11
  • Don't understand why the Parent would be null...in this case I think you're forcing it to open wherever it wants since it's parentless. But not sure. – Shawn Wildermuth May 04 '12 at 03:19
  • Also, GestureService is depreciated. Are you writing this against the 7.1 SDK (e.g. Mango)? If so, you should just use Tap not the GestureListener. – Shawn Wildermuth May 04 '12 at 03:19
  • @ShawnWildermuth thanks, I updated the code to get rid of the old GestureListener... Still doing the same thing (no surprise). Not sure about the null parent thing.. I was just following the example from the article above. – Microsis May 04 '12 at 07:50
  • You might be able to set the VerticalOffset property of the ContextMenu - http://windowsphonegeek.com/articles/WP7-ContextMenu-in-depth--Part1-key-concepts-and-API – Paul Diston May 04 '12 at 08:00
  • @PaulDiston thanks for the suggestion. Looks like it's a static vertical offset from the top of the screen. Do you know of some way I can set this value to match what it would be if it was working as intended (grabbing the "parent" vertical offset property or something?).. Not sure about this. – Microsis May 07 '12 at 05:18

0 Answers0