Formatting in WPF SpreadsheetControl (Classic)

4 May 20212 minutes to read

Conditional Formatting

Conditional formatting is a feature by which cell styles will be dynamically formatted based on its value and specified condition. It enables you to apply formatting to the cell through a dialog window.

Use Case Scenarios

This feature enables you to categorize the cell for analysis. For example, you can format a time sheet, to point out the overtime obtained by an employee. You can also use it to track the best sales employees in the company, by setting a quota that makes a cell range particular.

Defining Condition for Spreadsheet Cells

You can define the condition for formatting the Spreadsheet cells using a conditional formatting dialog box. Specify the conditional value and style format in the dialog box. You can open the conditional formatting dialog using the ConditionalFormatCommand. Based on the Command parameter one of the following dialogs will open:

  • Greater than


  • Less Than


  • Between


  • Equal to


The following code illustrates how to bind the ConditionalFormatCommand to a button:

  • XAML
  • <Button Command="{Binding Path=ConditionalFormatCommand}">


    Number formatting

    Number formatting helps you to control the format of the number in Spreadsheet cells. Number in the cell will be displayed based on the number format applied.

    Defining number formatting for Spreadsheet Cells

    You can define the number formatting using the NumberFormattingCommand. Number formatting will be applied to the Spreadsheet cells based on the command parameter. The following code illustrates this:

  • XAML
  • <Button Command="{Binding Path=NumberFormatCommand}" Grid.Row="2">


    Center Across Selection


    This feature center aligns the cell value in Spreadsheet, across the range of selected cells.


    Properties, Methods and Events


    Method Description Parameters Type Return Type
    SetCenterAcrossSelection() This method sets the Center Across Selection on the selected cells. It should be explicitly called to set Center Across Selection. setCenterAcrossSelection() null void

    Center aligning cell values in Spreadsheet

    The following code snippets manually set the center across selection by calling the method:


    The following code snippet manually sets the center across selection by calling the command:

  • XAML
  • <Button Content="CentreAcrossSelection" Margin="5" Width="200" Command="{Binding ElementName=spreadSheetControl, Path=CenterAcrossSelectionCommand}"/>

    The output displayed is shown in the following screenshot: