The issue is practically the same as described here: http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/542b827a-7c8e-4984-9158-9d8479b2d5b1 but I am not satisfied with the answer accepted there and feel that there must be a better solution...
I am trying to implement a 'clasic' context menu on my list view (not via the AppBar but via PopupMenu) and that works fine, however only if I set the list view into the "None" SelectionMode.
The link above correctly explains that the ListViewItem 'swallows' the right tapped event if ListView set to other than "None" selection mode. How can I override this behavior, so that the list view items gets selected AND the list view still fires the RightTapped event which I can react on?
I believe I solved the problem by subclassing both ListView and ListViewItem classes.
By this simple approach MyListView_RightTapped handler is called even if SelectionMode is set to 'Single', 'Multiple' or 'Extended'. Next question however is whether this small victory leads to a good design of the application UI. I will not try to answer that question here...
You can use PointerPressed/PointerReleased events on the GridViewItem to get the same effect you would otherwise get from RightTapped or ManipulationCompleted.
.
Output:
Press Release Press Release
*EDIT
Sorry, I must have missed it somehow that these events work differently with touch and mouse. I think the answers you got might be the best you will get. Otherwise - you would need to implement your own version of a ListView. You could try pressuring them with hope to get a better solution in one of the future releases, but I would not hope for much there. From what I remember - ContextMenus are not very metro and there are better UX solutions than right-click menus. You can display the commands in the AppBar or on a details page that opens after you select an item. That could work better than trying to hack a workaround for something that was never designed to be supported.
I took @Jan Zeman's idea ( upvoted, by the way ;) ) and improved it a bit.
A few problems with the original approach:
e.Handled = true
, or else the event will bubble up, until thePage
itself handles the right tap event - and consequently opens the app bar.Page
.This approach solves the problems above:
Now you can subscribe to the
ItemRightTapped
event instead, which will be triggered if and only if an item is right tapped.The item will mark the event as unhandled, the list will let you handle the event, and then mark it as handled - preventing it from bubbling up and hitting the
Page
.