.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
.NET Core 3.0+

XafApplication.ViewCreating Event

Occurs when creating a View.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v21.1.dll


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.


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() {
            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() {
            Application.ViewCreating -= Application_ViewCreating;

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

See Also