IObjectSpace.ObjectChanged Event
Occurs when a persistent object is created, deleted or changed (when the objects’ INotifyPropertyChanged.PropertyChanged event occurs).
Namespace: DevExpress.ExpressApp
Assembly: DevExpress.ExpressApp.v24.2.dll
NuGet Package: DevExpress.ExpressApp
#Declaration
event EventHandler<ObjectChangedEventArgs> ObjectChanged
#Event Data
The ObjectChanged event's data class is ObjectChangedEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Member |
Specifies an object that is information on the property whose value has been changed. |
New |
Specifies the new value of a changed property. |
Object |
Provides access to the object that is being manipulated.
Inherited from Object |
Old |
Specifies the old value of a changed property. |
Property |
Specifies the name of a property whose value has been changed. Returns null (Nothing in VB) if it is impossible to determine what property causes the change. |
#Remarks
You can handle this event in a custom Controller to execute business logic when an object is changed.
The following example illustrates how to update the TotalPrice property of a Sale object when its Count property is changed.
using DevExpress.ExpressApp;
public class MyViewController : ObjectViewController<ObjectView, Sale> {
protected override void OnActivated() {
base.OnActivated();
ObjectSpace.ObjectChanged += ObjectSpace_ObjectChanged;
}
private void ObjectSpace_ObjectChanged(object sender, ObjectChangedEventArgs e) {
if (e.PropertyName == nameof(Sale.Count)) {
Sale sale = (Sale)e.Object;
sale.TotalPrice = sale.Count * sale.Price;
}
}
protected override void OnDeactivated() {
base.OnDeactivated();
ObjectSpace.ObjectChanged -= ObjectSpace_ObjectChanged;
}
}
Note
Business objects must implement the INotify
For object changes that cannot be tracked via notification mechanisms exposed by the data layer, the IObjectSpace.SetModified method must be called after an object has been changed. This method adds the object passed as the obj parameter to the list of objects to be committed.
If you implement the IObjectSpace interface in the BaseObjectSpace class’ descendant, you don’t have to declare this event. It’s declared within the BaseObjectSpace class. The BaseObjectSpace.OnObjectChanged method raises this event. So, you should only invoke the OnObjectChanged method in your BaseObjectSpace.SetModified method override.
Note
In XPO, the Objectnull
). In EF Core, these parameters return values only for objects that implement the INotify
#Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the ObjectChanged event.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.