expressappframework-devexpress-dot-expressapp-dot-xafapplication-40d2c6d9.md
Occurs when creating a View.
Namespace : DevExpress.ExpressApp
Assembly : DevExpress.ExpressApp.v25.2.dll
NuGet Package : DevExpress.ExpressApp
public event EventHandler<ViewCreatingEventArgs> ViewCreating
Public Event ViewCreating As EventHandler(Of ViewCreatingEventArgs)
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() {
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:
ViewCreating event is set to null;ViewCreating event is set to the object from the List View’s Object Space.See Also