Skip to content

Substitute the default command factory service with its descendant to create a custom command in place of the default command.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/wpf-spreadsheet-how-to-replace-standard-command-with-custom-command

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WPF Spreadsheet - How to replace a standard command with a custom Command

This example demonstrates how to modify the functionality of the existing SpreadsheetControl command used to clear the selected cell content. All commands in the SpreadsheetControl are created using the command factory service. You can substitute the default command factory service with its descendant to create a custom command in place of the default command.

Implementation Details

Follow the steps below.

  1. Create a custom command class inherited from the command you wish to replace. In this example, it is DevExpress.XtraSpreadsheet.Commands.FormatClearContentsCommand. Override the ExecuteCore method to specify actions that the command should perform.
  2. Create a class inherited from SpreadsheetCommandFactoryServiceWrapper to replace the default command service. In this class, override the CreateCommand method to substitute the default FormatClearContents and FormatClearContentsContextMenuItem commands with the newly created custom command.
  3. Create a custom service instance and use the SpreadsheetControl.ReplaceService method to replace the default service with the custom one. Note that due to WPF Spreadsheet implementation specifics, it is necessary to replace the built-in service after the control is completely loaded.

Files to Review

CS VB
MainWindow.xaml MainWindow.xaml
MainWindow.xaml.cs MainWindow.xaml.vb
CustomCommandService.cs CustomCommandService.vb

Documentation

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Substitute the default command factory service with its descendant to create a custom command in place of the default command.

Topics

Resources

License

Stars

Watchers

Forks