Skip to main content
.NET Framework 4.6.2+

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
MemberInfo Specifies an object that is information on the property whose value has been changed.
NewValue Specifies the new value of a changed property.
Object Provides access to the object that is being manipulated. Inherited from ObjectManipulatingEventArgs.
OldValue Specifies the old value of a changed property.
PropertyName 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 INotifyPropertyChanged interface. See this article for details: The Importance of Property Change Notifications for Automatic UI Updates.

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 ObjectChangedEventArgs.OldValue and ObjectChangedEventArgs.NewValue parameters return values only if corresponding values are passed to the SetPropertyValue or OnChanged method (otherwise, the parameters return null). In EF Core, these parameters return values only for objects that implement the INotifyPropertyChanging and INotifyPropertyChanged interfaces. These interfaces are automatically added to business objects when the UseChangeTrackingProxies option is enabled (the default configuration in new projects). For more information, see The Importance of Property Change Notifications for Automatic UI Updates.

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.

See Also