How to close menu anchor by clicking anywhere else?

I have an inventory system and i am using a menu anchor for the context menu. The problem is that it only disappears if i click a button inside it and then anywhere else, if i just click anywhere else after it opened it will not close. Does anyone know a fix or a workaround?

I found a workaround that works for now: I put a button in the back that covers the whole screen and when that is pressed I call the menu anchors close function (this means that i have to call that function on every other button if i want it to close even when i click on something). It works for now but I’m still looking for a better solution.

I am stuck on the same issue recently, and I found a solution. Hope it is still related.

  1. Set the IsFocusable of the target widget(the widget which the MenuAnchor is supposed to open) to true.
  2. Call SetUserFocus via the the target widget right after it is opened by MenuAnchor.

There is actually built-in functionality for this. If you check the “Focus Menu” option on the Open node then the Menu Anchor will put focus into the menu when it is created and will automatically close it when focus leaves the menu (which happens when you click anywhere else).

3 Likes

Thank you so much! You helped me a lot.