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;
}
}