Page 1 of 1

Adding Context menu to TreeviewItem

Posted: 22 Sep 2022, 18:47
by ZGholson
Hello,

We are looking at adding a context menu that works with controller to a TreeViewItem or the TreeView. The plan is to have the context menu open next to the item in the list and immediately take focus after we left click or press the select button on the TreeViewItem.

The two challenges are:
  • Copying the right click functionality to On Item Selected for controller
  • Opening the contextmenu next to the treeviewitem with focus.
Any suggestions are welcome here.

Thank you

Re: Adding Context menu to TreeviewItem

Posted: 23 Sep 2022, 21:06
by sfernandez
Hi,

A ContextMenu can be manually open by setting the IsOpen property to true, so you can do that in response to a specific key/button in the gamepad (with a KeyTrigger/GamepadTrigger in xaml for example). And by setting ContextMenu's Placement="Right", it will be opened on the right of its owner (you can tweak the position adjusting the HorizontalOffset and VerticalOffset properties too). The ContextMenu could be defined as part of the TreeViewItem template or in one element of the HeaderTemplate.

Once the ContextMenu is opened it gets automatically focused and you should be able to navigate up and down through the items, but I found a bug in MenuItem code that breaks directional navigation when the menu is placed inside a ListBox or TreeView. Could you please report this in our bugtracker and we will fix it for the next release?

Re: Adding Context menu to TreeviewItem

Posted: 23 Sep 2022, 23:22
by ZGholson
Thank you for looking into that. The issue has been submitted to the tracker under ticket #2431.

Re: Adding Context menu to TreeviewItem

Posted: 27 Sep 2022, 11:38
by sfernandez
Thanks for the report.