可以通过实现 IUndo 实现Undo 功能,可以直接通过ctrl z 撤销。
- public partial class MainPage : UserControl
- {
- public MainPage()
- {
- InitializeComponent();
- }
- private void button_Click(object sender, RoutedEventArgs e)
- {
- var action = new SetColorAction();
- gcSpreadSheet1.DoCommand(action);
- }
- }
- public class SetColorAction : ActionBase, IUndo
- {
- public bool CanUndo
- {
- get
- {
- return true;
- }
- }
- public override bool CanExecute(object parameter)
- {
- return true;
- }
- public override void Execute(object parameter)
- {
- var spread = parameter as SpreadView;
- this._oldColor = spread.ActiveSheet.ActiveCell.Background;
- this._cellRow = spread.ActiveSheet.ActiveRowIndex;
- this._cellColumn = spread.ActiveSheet.ActiveColumnIndex;
- spread.ActiveSheet.Cells[this._cellRow, this._cellColumn].Background =
- new System.Windows.Media.SolidColorBrush(Colors.Red);
- }
- private Brush _oldColor;
- private int _cellRow;
- private int _cellColumn;
- public void SaveState()
- {
- }
- public bool Undo(object parameter)
- {
- var spread = parameter as SpreadView;
- spread.ActiveSheet.Cells[this._cellRow, this._cellColumn].Background =
- this._oldColor;
- return true;
- }
- }
复制代码 |