Back to Devexpress

BaseObjectSpace.ModifiedChanging Event

expressappframework-devexpress-dot-expressapp-dot-baseobjectspace-a332dddf.md

latest5.3 KB
Original Source

BaseObjectSpace.ModifiedChanging Event

Occurs before the IsModified property is changed to true. Handle this event to cancel the property change or force the IsModified property to change.

Namespace : DevExpress.ExpressApp

Assembly : DevExpress.ExpressApp.v25.2.dll

NuGet Package : DevExpress.ExpressApp

Declaration

csharp
public event EventHandler<ObjectSpaceModificationEventArgs> ModifiedChanging
vb
Public Event ModifiedChanging As EventHandler(Of ObjectSpaceModificationEventArgs)

Event Data

The ModifiedChanging event's data class is ObjectSpaceModificationEventArgs. The following properties provide information specific to this event:

PropertyDescription
CancelSpecifies whether the IsModified property change must be canceled.
MemberInfoSpecifies an object that is information on the property whose value has been changed. Inherited from ObjectChangedEventArgs.
NewValueSpecifies the new value of a changed property. Inherited from ObjectChangedEventArgs.
ObjectProvides access to the object that is being manipulated. Inherited from ObjectManipulatingEventArgs.
OldValueSpecifies the old value of a changed property. Inherited from ObjectChangedEventArgs.
PropertyNameSpecifies the name of a property that had its value changed. Returns null if it is impossible to determine what property causes the change. Inherited from ObjectChangedEventArgs.

Remarks

The following example shows how to cancel the IsModified property change when you modify the Category property of a ProductView object. In this case, the current Object Space does not add this object to the ModifiedObjects collection.

File: MySolution.Blazor.Server/Startup.cs, MySolution.Win/Startup.cs, MySolution.WebApi/Startup.cs

csharp
using DevExpress.ExpressApp;
// ...
builder.ObjectSpaceProviders.Events.OnObjectSpaceCreated = context => {
    var npos = context.ObjectSpace as NonPersistentObjectSpace;
    if (npos != null) {
        npos.ModifiedChanging += Npos_ModifiedChanging;
    }
};
// ...
private void Npos_ModifiedChanging(object sender, ObjectSpaceModificationEventArgs e) {
    if(e.MemberInfo!= null) {
        if(e.MemberInfo.Owner.Type == typeof(ProductView) && 
        e.MemberInfo.Name == nameof(ProductView.Category)) {
            e.Cancel = true;
        }
    }
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the ModifiedChanging 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.

XAF_Non-Persistent-Objects-Edit-Linked-Persistent-Objects-Demo/CS/EFCore/NonPersistentEditEF/NonPersistentEditEF.Module/BusinessObjects/ProductViewAdapter.cs#L12

csharp
objectSpace.Reloaded += ObjectSpace_Reloaded;
    objectSpace.ModifiedChanging += ObjectSpace_ModifiedChanging;
}

See Also

How to edit a collection of Persistent Objects linked to a Non-Persistent Object

BaseObjectSpace Class

BaseObjectSpace Members

DevExpress.ExpressApp Namespace