Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+

BaseObjectSpace.ObjectChanged Event

Raised when a persistent object is created, changed or deleted.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v19.2.dll

Declaration

public 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

This event must be raised by the BaseObjectSpace class’ descendants.

The ObjectChanged event is raised both when an object is changed directly and by means of controls. When the ObjectChanged event is raised, the object change has not yet been saved to the database.

The ObjectChangedEventArgs.OldValue and ObjectChangedEventArgs.NewValue parameters return values only for XPO persistent objects and only if corresponding values are passed to the SetPropertyValue or OnChanged method. If you use Entity Framework or non-persistent objects, the OldValue and NewValue parameters always return null (Nothing in VB). This is expected behavior, because Entity Framework doesn’t provide an event that the Object Space can handle to get the modified property’s old and new values. The INotifyPropertyChanged interface passes the property name only. In this scenario, you can get a new value directly from the property. Note that the required property should be implemented as described in the PropertyChanged Event in Business Classes article and decorated with the ImmediatePostDataAttribute. The example below demonstrates how to get a new value from the EffectiveDate property.

using DevExpress.ExpressApp;
//...
public class MyExampleViewController : ObjectViewController<DetailView, DemoObject> {
    private void ObjectSpace_ObjectChanged(object sender, ObjectChangedEventArgs e) {
        if (ViewCurrentObject != null) {
            if (e.PropertyName == "EffectiveDate") {
                ViewCurrentObject.RetroDate = ViewCurrentObject.EffectiveDate;
            }
        }
    }
    protected override void OnActivated() {
        base.OnActivated();
        View.ObjectSpace.ObjectChanged += ObjectSpace_ObjectChanged;
    }
    protected override void OnDeactivated() {
        base.OnDeactivated();
        View.ObjectSpace.ObjectChanged -= ObjectSpace_ObjectChanged;
    }
}

Implements

See Also