In the object that is set in the DataContext (ideally, it should be a ViewModel in the MVVM approach), output two commands
public ICommand CancelCommand { get; set; } public ICommand OkCommand { get; set; }
Then, these commands are assigned to the buttons, as shown below.
<Button Command="{Binding CancelCommand}" ... />
You must save two copies of the object, a copy must be created by Deep Copy, or if the object has several editable fields, you can save them as a field class. Basically, at the initialization stage, make backup copies of the properties of the object, and then bind to the DataContext editable version of the object. In the command cancel handler, restore from backup ...
source share