Skip to main content
.NET 8.0+

XafApplication.ViewCreating Event

Occurs when creating a View.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v24.2.dll

NuGet Package: DevExpress.ExpressApp

Declaration

public event EventHandler<ViewCreatingEventArgs> ViewCreating

Event Data

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

Property Description
IsRoot Indicates whether a root View must be created.
ObjectSpace Returns the Object Space to be used when creating a new View.
View Specifies a custom View created in a XafApplication.DetailViewCreating or XafApplication.ListViewCreating event.
ViewID Returns the ID of the created View.

Remarks

Handle this event to provide a custom View instead of a default one. Use the handler’s ViewCreatingEventArgs.View parameter to get information on the View being created. To do this, use the application’s XafApplication.FindModelView method passing the View ID as a parameter.

To specify the Detail View’s current object use the handler’s DetailViewCreatingEventArgs.Obj parameter. Create the Detail View in the Object Space passed as the handler’s ViewCreatingEventArgs.ObjectSpace parameter.

To create a List View, use the collection source passed as the handler’s ListViewCreatingEventArgs.CollectionSource parameter. To specify whether the List View is root, use the handler’s ViewCreatingEventArgs.IsRoot parameter.

The following example demonstrates how to handle the ViewCreating event:

using DevExpress.ExpressApp;

namespace MySolution.Module.Controllers {
    public class MyWindowController : WindowController {
        public MyWindowController() {
            TargetWindowType = WindowType.Main;
        }
        protected override void OnActivated() {
            base.OnActivated();
            Application.ViewCreating += Application_ViewCreating;
        }
        void Application_ViewCreating(object sender, ViewCreatingEventArgs e) {
            if (e.ViewID == "Contact_DetailView") {
                var os = Application.CreateObjectSpace(typeof(MyTask));
                var obj = os.CreateObject<MyTask>();
                obj.Subject = "New MyTask";
                var view = Application.CreateDetailView(os, obj);
                e.View = view;
            }
        }
        protected override void OnDeactivated() {
            base.OnDeactivated();
            Application.ViewCreating -= Application_ViewCreating;
        }
    }
}

Note

If DetailView.UseAsyncLoading is set to true, note the following:

  • when you open a Detail View from the Navigation, the DetailViewCreatingEventArgs.Obj argument of the ViewCreating event is set to null;
  • when you open a Detail View from a List View (by double-clicking a record or using the OpenObject Action), the DetailViewCreatingEventArgs.Obj argument of the ViewCreating event is set to the object from the List View’s Object Space.
See Also