Lesson 2 - Create Separate Ribbon Pages for the Spreadsheet

  • 2 minutes to read

This document describes how you can add a ribbon UI to the WPF Spreadsheet to provide end-users with a familiar Office-inspired interface with rich spreadsheet functionality.

NOTE

The mechanism of ribbon generation described in this document is outdated and retained for backward compatibility. The newly created WPF Spreadsheet application already contains the integrated ribbon with all available ribbon pages and a formula bar in v17.1 and higher. This makes the XAML markup compact and more readable. You can customize the integrated ribbon user interface by adding new ribbon elements, modifying or removing the existing ones. Refer to the Lesson 4 - Customize the Integrated Ribbon UI for the Spreadsheet topic for example.

This tutorial consists of the following sections:

Create a Spreadsheet Application

  1. Create a new WPF Application project and open the MainWindow.xaml file in the Visual Studio Designer.
  2. Add the SpreadsheetControl object to your project. You can do this by dragging the SpreadsheetControl item from the DX.19.2: Spreadsheet Toolbox tab to the canvas.

    DXSpreadsheet_GettingStarted_DropFromToolbox

  3. Right-click the SpreadsheetControl object and select Layout | Reset All in the context menu to stretch the SpreadsheetControl so that it fills the entire window.
  4. Click the SpreadsheetControl's smart tag. In the invoked menu, under Integrated Ribbon and Formula Bar, select Empty from the CommandBarStyle drop-down list to disable the integrated ribbon UI.

    DXSpreadsheet_GettingStarted2_DisableIntegratedRibbon

Create Ribbon Pages

  1. To create separate ribbon pages, click the SpreadsheetControl's smart tag, and in the invoked menu, under Create Separate Ribbon Pages, select the ribbon pages you wish to add to your application or click All to display all available spreadsheet ribbon pages at once.

    DXSpreadsheet_GettingStarted2_CreateAllPages

  2. Convert the Window to ThemedWindow. To do this, click the Window's smart tag and select the Convert to ThemedWindow task.

    DXSpreadsheet_GettingStarted2_ConvertWindow

  3. Change the Ribbon Style by clicking the RibbonControl's smart tag and setting the RibbonStyle property to Office 2010.

    DXSpreadsheet_GettingStarted2_ConvertRibbon

View the Result

Run the project. The following image illustrates the result:

SpreadsheetControl_WPF_GetStarted_RibbonResult

NOTE

Commands executed via the Bar (Ribbon) user interface can throw unhandled exceptions if a problem occurs. Consider the situation when a document is being saved to a locked or read-only file. To prevent application failure, subscribe to the SpreadsheetControl.UnhandledException event and set the SpreadsheetUnhandledExceptionEventArgs.Handled property to true.