How to use ContextMenuService in WPF

ContextMenuService class provides the system implementation for displaying a ContextMenu on an event. For example, displaying click event handler. When this menu is clicked, the code written on this event handler will be executed.

The following code snippet sets a ContextMenuService of a button and sets ShowOnDisabled to true.

<Button Height="30" Content="ContextMenuService Button" IsEnabled="False"

    ContextMenuService.ShowOnDisabled="True" Canvas.Top="220" Canvas.Left="20"

        ContextMenuService.HasDropShadow="True" Width="200">

    <Button.ContextMenu>

        <ContextMenu>

            <MenuItem Header="Red"/>

            <MenuItem Header="Green"/>

            <MenuItem Header="Orange"/>

        </ContextMenu>

    </Button.ContextMenu>

</Button>