The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
.NET Core 3.0+

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
Public Event ObjectChanged As EventHandler(Of ObjectChangedEventArgs)
public event EventHandler<ObjectChangedEventArgs> ObjectChanged
Public Event ObjectChanged As EventHandler(Of ObjectChangedEventArgs)
public event EventHandler<ObjectChangedEventArgs> ObjectChanged
Public Event ObjectChanged As EventHandler(Of ObjectChangedEventArgs)

Event Data

The ObjectChanged event handler receives an argument of the ObjectChangedEventArgs type. 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;
    }
}
See Also