有没有撤销功能的代码可以参考。
有没有撤销功能的代码可以参考。您的问题我已经收到,稍后给您发个Demo 可以通过实现 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.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.Background =
this._oldColor;
return true;
}
}
页:
[1]