Using Binding within multiple DialogWindows - canceling issue
I'm building an application that supports customers and their purchases. Each customer holds a list of purchases:
public class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Address { get; set; }
public DateTime DateOfBirth { get; set; }
... //Some more properties...
public List<Purchase> PurchasesList { get; set; }
}
public class Purchase
{
public string ProductName { get; set; }
public int ProductSerialNumber { get; set; }
public DateTime DateOfPurchase { get; set; }
...//Some more properties
}
And I hold a list of customers:
public List<Customer> Customers { get; set; }
At some point I want to edit the customers' list and their purchases. To do that I bind the Customers' list to a ListView control in a DialogWindow (#1). When the user double-clicks one of the customers, a new DialogWindow (#2) is opened that allows editing the customer's personal details and his purchases - most of them are textboxes that allow editing and I bind them to the customer object within the customers' list. When the user presses 'OK' button - the binding is performed (I chose UpdateSourceTrigger.Explicit on all textboxes).
Dialog (#2) is now closed and the changes took place (I can see the changes on the ListView on Dialog (#1)). The problem is if the user presses the 'Cancel' button on Dialog (#1) he expects that the changes will not take place开发者_JAVA技巧 (but actually the source had already been updated).
How can I undo the changes? I don't want to hold a copy of Customers' list (this might be a very space consuming list)
There is an interface called IEditableObject, it is quite complex to use but it might be helpful, since it exists for that exact purpose: Cancelling edits.
You might not get around saving a copy of your list though unless you take note of exactly which items were edited and just store their original state.
精彩评论