CancelEdit Doesn't Work

CancelEdit Doesn't Work

Old forum URL: forums.lhotka.net/forums/t/12026.aspx


tsvideo posted on Monday, June 17, 2013

What all can be, if call of Model.CancelEdit() Doesn't Work ?

The Model IsDirty and e.g. Save can Execute.
It's a WPF Application with MVVM (own ViewModelBase).
The call of Model.CancelEdit() runs, but no changed Property are reset to the original value.
It's a Parent Model with Csla Propertys and Csla ChildLists Propertys.

JonnyBee replied on Monday, June 17, 2013

Are you sure BeginEdit has been called first to create an initial snapshot? 

Check Model.EditLevel - it should be > 0 before you call CancelEdit

tsvideo replied on Tuesday, June 18, 2013

Hello Jonny,
Yes, this did the trick, i have to call first, after Loading the Model, the Model.BeginEdit() function to get an Snapshot.
I thought it was automaticaly called, but it didn't.
Rockys Post http://forums.lhotka.net/forums/p/6861/32872.aspx#32872 explained it.

But, to get Model.EditLevel (Using CSLA 4.5.30) i have to cast it to Csla.Core.IUndoableObject
Is that right ?
I would use it in the Undo Command Button CanExecute to examine if the Undo Button is On or Off.

JonnyBee replied on Tuesday, June 18, 2013

Hi,

I think BeginEdit is only called if the ViewModel has ManageLifeTime = true.

Yes this is correct. You need to cast the object IUndoableObject.

Copyright (c) Marimer LLC