Back to Devexpress

View.CurrentObjectChanged Event

expressappframework-devexpress-dot-expressapp-dot-view-50f6c04a.md

latest5.0 KB
Original Source

View.CurrentObjectChanged Event

Occurs after changing a View’s focused object (not an object’s property value).

Namespace : DevExpress.ExpressApp

Assembly : DevExpress.ExpressApp.v25.2.dll

NuGet Package : DevExpress.ExpressApp

Declaration

csharp
public event EventHandler CurrentObjectChanged
vb
Public Event CurrentObjectChanged As EventHandler

Event Data

The CurrentObjectChanged event's data class is EventArgs.

Remarks

This event is raised in methods of the View class descendants:

Important

Do not mix a View’s focused object changes with property value changes. To track object instance’s changes, handle the IObjectSpace.ObjectChanged, INotifyPropertyChanged.PropertyChanged or other suitable events.

The following example demonstrates how to use the CurrentObjectChanged event to make a View read-only:

csharp
public class MyController : ViewController {
    protected override void OnActivated() {
        base.OnActivated();
        View.CurrentObjectChanged += View_CurrentObjectChanged;
        View_CurrentObjectChanged(View, new EventArgs());
    }
    private void View_CurrentObjectChanged(object sender, EventArgs e) {
       if (View.CurrentObject is Task) {
            View.AllowEdit["CurrentUser"] = ((Task)View.CurrentObject).Owner.Id == SecuritySystem.CurrentUserId;
       }
    }
    protected override void OnDeactivated() {           
        View.CurrentObjectChanged -= View_CurrentObjectChanged;
        base.OnDeactivated();
    }
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the CurrentObjectChanged 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-how-to-highlight-invalid-properties-when-a-view-is-activated/CS/EFCore/ValidateHighlightEF/ValidateHighlightEF.Module/Controllers/ImmediateValidationController.cs#L26

csharp
ObjectSpace.ObjectReloaded += ObjectSpace_ObjectReloaded;
    View.CurrentObjectChanged += View_CurrentObjectChanged;
}

xaf-how-to-dynamically-change-mask-settings-based-on-the-current-object/CS/EFCore/DynamicMaskEF/DynamicMaskEF.Module/Controllers/ChangeMaskControllerBase.cs#L15

csharp
View.CustomizeViewItemControl<PropertyEditor>(this, PropertyEditorCreated, nameof(DemoObject.TestString));
View.CurrentObjectChanged += View_CurrentObjectChanged;
ObjectSpace.ObjectChanged += ObjectSpace_ObjectChanged;

xaf-how-to-access-the-master-detailview-information-from-a-nested-listview-controller/CS/EFCore/GetMasterFrameEF/GetMasterFrameEF.Module/Controllers/MyTaskController.cs#L20

csharp
base.OnActivated();
View.CurrentObjectChanged += View_CurrentObjectChanged;
UpdateMasterFrameAction();

See Also

CurrentObject

CurrentObject

ValueStored

View Class

View Members

DevExpress.ExpressApp Namespace