How can I add a context menu to UI element in MAUI?

Nikolay Kusch 6 Reputation points

The code below is not working, Error XLS0415 The attachable property 'ContextActions' was not found in type 'Grid'

    <MenuItem Text="Test"/>  
    <MenuItem Text="Test 2"/>  
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,851 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 26,146 Reputation points Microsoft Vendor

    Hello @Nikolay Kusch ,

    There is no ContextActions for Grid in MAUI, only ListView supports context menus items. As described in ListView - .NET MAUI | Microsoft Learn : ListView supports context menus items, which are defined as MenuItem objects that are added to the ViewCell.ContextActions collection in the DataTemplate for each item

    If you want to add context menus to other UI element, please check SwipeView - .NET MAUI | Microsoft Learn.

    Best Regards,
    Wenyan Zhang

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.