Can you think of a scenario where IEditableObject
would be still usefull in an MVVM-based WPF application? If so, do you have an example that demonstrates this.
I have used IEditableObject
in one of my applications. For example if you have a dialog for editing something, you could implement IEditableObject on your ViewModel. You call BeginEdit()
when the dialog opens, EndEdit()
when the user clicks OK, and CancelEdit()
when the user clicks cancel.
IEditableObject
is a good interface anytime you want to be able to roll back changes.
I've got an implementation of IEditableObject
in my application so that I can keep from updating my data model if what the user has entered is invalid, and roll back to the original values if the user abandons changes.
Within a type being displayed in a DataGrid
. This was needed since when I am making use of tabs and a DataGrid
is being stored within that tab switching the tabs needed to force a commit so to speak within the DataGrid
if a cell was active; rolling back the changes since they were not committed. T
There is a behavior being applied to the DataGrid
to achieve this functionality but the IEditableObject
portion is below.
private IDatabaseConnection _copy;
void IEditableObject.BeginEdit()
{
if (this._copy == null)
this._copy = _container.Resolve<IDatabaseConnection>();
_copy.Database = this.Database;
_copy.DisplayName = this.DisplayName;
_copy.HostName = this.HostName;
_copy.Username = this.Username;
_copy.Password = this.Password;
}
void IEditableObject.CancelEdit()
{
this.Database = _copy.Database;
this.DisplayName = _copy.DisplayName;
this.HostName = _copy.HostName;
this.Username = _copy.Username;
this.Password = _copy.Password;
}
void IEditableObject.EndEdit()
{
_copy.Database = String.Empty;
_copy.DisplayName = String.Empty;
_copy.HostName = String.Empty;
_copy.Username = String.Empty;
_copy.Password = String.Empty;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With