If you meant to cancel all changes in Product
, all of it, as if you just opened a new ProductEdit
Window, why not simply create a new Product :
private void btReset_Click(object sender, RoutedEventArgs e)
{
Product = new Product();
}
As what you did in constructor. Previously created Product
object hasn't been added to DataContext, hence will not be saved later when user click Save button. This seems to be too straightforward, I suspect I missed something in your situation (._.)?
Is there any problem with this approach which I can't see it?
UPDATE :
Assuming that you get Product from DbContext instead of create it new, then you want to cancel all edit made so that Product property values remain as it originally stored in DbContext, you can try to do it by changing Product's State property as follow :
db.Entry(Product).State = EntityState.Unchanged;
See this blog post about Rejecting changes to entities in EF 4.1.