Version

Create Custom Context Menu (XamSpreadsheet)

Purpose

This topic explains how to create your own context menu.

Required background

The following table lists the concept and topics required as a prerequisite to understanding this topic.

Type Content

Concept

Infragistics Excel Engine

Topic Purpose

In this section you will find information that will help you to better understand the object model and the functionalities of the Infragistics Excel Engine .

In this topic you’ll find information that will help you understand the functionalities of the xamContextMenu control.

This topic explains in details the features of the XamSpreadsheet control from developer perspective.

This topic provides an overview of the visual elements of the XamSpreadsheet control.

This topic explains what operations can be performed by the user with the control’s context menu.

In this topic

This topic contains the following sections:

Create Custom Context Menu

Process summary

Although the XamSpreadsheet control supports built-in context menus for all its major areas you can define your own custom context menu(s).

To create custom context menu(s) do the following:

  1. Create an instance of SpreadsheetContextMenuProvider and set it to the ContextMenuProvider property of the XamSpreadsheet.

  2. Create a ResourceDictionary and set it to the SpreadsheetContextMenuProvider.ResourceOverrides property.

  3. Add one or more instances of the xamContextMenu control to the resource dictionary from step 2 to customize the XamSpreadsheet’s context menu(s) of your choice.

Note
Note

The XamSpreadsheet instances should have a "x:Key" specified with a predefined value from the SpreadsheetContextMenuArea enumeration to allow the control to properly override the correct context menu.

Code Example: Create Custom Context Menu

Description

This example demonstrates how to define a context menu on the xamSpreadsheet’s "cells" area with the following options:

  • toggle bold

  • toggle italic

  • navigate cell above

  • navigate cell below

  • navigate cell left

  • navigate cell right

Code

Following is the code that implements this example.

In XAML:

<Page
  …
  xmlns:ig="http://schemas.infragistics.com/xaml"
  xmlns:igPrim="http://schemas.infragistics.com/xaml/primitives">
<ig:XamSpreadsheet>
  <ig:XamSpreadsheet.ContextMenuProvider>
    <ig:SpreadsheetContextMenuProvider>
      <ig:SpreadsheetContextMenuProvider.ResourceOverrides>
        <ResourceDictionary>
          <ig:XamContextMenu x:Key="Cell">
            <ig:XamContextMenu.DataContext>
              <igPrim:SpreadsheetMenuDataContext />
            </ig:XamContextMenu.DataContext>
            <ig:XamMenuItem Header="Bold">
              <ig:XamMenuItem.Icon>
                <Image Source="/Assembly;component/Folder/Bold.png" />
              </ig:XamMenuItem.Icon>
              <ig:Commanding.Command>
                <igPrim:SpreadsheetCommandSource
                  CommandType="ToggleBold" EventName="Click" />
              </ig:Commanding.Command>
            </ig:XamMenuItem>
            <ig:XamMenuItem Header="Italic">
              <ig:XamMenuItem.Icon>
                <Image Source="/Assembly;component/Folder/Italic.png" />
              </ig:XamMenuItem.Icon>
              <ig:Commanding.Command>
              <igPrim:SpreadsheetCommandSource
                CommandType="ToggleItalic" EventName="Click" />
              </ig:Commanding.Command>
            </ig:XamMenuItem>
            <ig:XamMenuSeparator />
            <ig:XamMenuItem Header="Navigate Up">
              <ig:Commanding.Command>
                <igPrim:SpreadsheetCommandSource
                  CommandType="CellAbove" EventName="Click" />
              </ig:Commanding.Command>
            </ig:XamMenuItem>
            <ig:XamMenuItem Header="Navigate Down">
              <ig:Commanding.Command>
                <igPrim:SpreadsheetCommandSource
                  CommandType="CellBelow" EventName="Click" />
              </ig:Commanding.Command>
            </ig:XamMenuItem>
            <ig:XamMenuItem Header="Navigate Left">
              <ig:Commanding.Command>
                <igPrim:SpreadsheetCommandSource
                  CommandType="CellLeft" EventName="Click" />
              </ig:Commanding.Command>
            </ig:XamMenuItem>
            <ig:XamMenuItem Header="Navigate Right">
              <ig:Commanding.Command>
                <igPrim:SpreadsheetCommandSource
                  CommandType="CellRight" EventName="Click" />
              </ig:Commanding.Command>
            </ig:XamMenuItem>
          </ig:XamContextMenu>
        </ResourceDictionary>
      </ig:SpreadsheetContextMenuProvider.ResourceOverrides>
    </ig:SpreadsheetContextMenuProvider>
  </ig:XamSpreadsheet.ContextMenuProvider>
</ig:XamSpreadsheet>

Related Content

The following topics provide additional information related to this topic.

Topic Purpose

This topic explains how to perform different operations with the control using commands.

This topic explains the activation feature from developer perspective.

This topic explains the selection feature from developer perspective.

This topic explains how to configure and perform undo and redo operations with the control.