Skip to content

jerry08/Plugin.ContextMenuContainer

Repository files navigation

ContextMenuContainer

Version Downloads

Maui plugin to add native context menu to any view. Supports all .NET MAUI platforms.

Usage

  1. Add the .ConfigureContextMenuContainer() in your MauiProgram.cs as shown below:
using Plugin.ContextMenuContainer;
builder
    .UseMauiApp<App>()
    .UseMauiCommunityToolkit()
    .ConfigureContextMenuContainer();
  1. Add namespace to your XAML file xmlns:cm="https://github.com/jerry08/Plugin.ContextMenuContainer"

  2. Wrap your view with ContextMenuContainer, define your context actions inline or bind from your ViewModel

//Inline
<cm:ContextMenuContainer x:Name="ActionsInline">
    <cm:ContextMenuContainer.MenuItems>
        <cm:ContextMenuItem
            Text="My action" 
            Command="{Binding MyCommand}" 
            CommandParameter="{Binding .}" />
        <cm:ContextMenuItem
            Text="My destructive action" 
            Command="{Binding MyDestructiveCommand}" 
            CommandParameter="{Binding .}" 
            IsDestructive="True" 
            Icon="{Binding DestructiveIconSource}"/>
    </cm:ContextMenuContainer.MenuItems>
    <cm:ContextMenuContainer.Content>
        <Label Text="Hold me!"/>
    </cm:ContextMenuContainer.Content>
</cm:ContextMenuContainer>
//From binding
<cm:ContextMenuContainer
    x:Name="ContextActionsWithBinding" 
    MenuItems="{Binding ImageContextItems}">
    <cm:ContextMenuContainer.Content>
        <Frame>
            <Image Source="{Binding IconSource}"/>
        </Frame>
    </cm:ContextMenuContainer.Content>
</cm:ContextMenuContainer>

About

Maui plugin to add native context menu to any view.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages