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

Nikolay Kusch 6 Reputation points
2022-08-26T03:12:34.843+00:00

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

<Grid.ContextActions>  
    <MenuItem Text="Test"/>  
    <MenuItem Text="Test 2"/>  
</Grd.ContextActions>  
.NET MAUI
.NET MAUI
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
    2022-08-29T08:35:44.297+00:00

    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.