How to: Create and Show a Detail View of the Selected Object in a Popup Window
- 2 minutes to read
This topic demonstrates a View Controller that creates and shows a Detail View of the List View’s selected object in a popup window.
Follow the steps below.
- Create a View Controller with the PopupWindowShowAction.
- Handle the Action’s PopupWindowShowAction.CustomizePopupWindowParams event.
- In the event handler, create an Object Space using the XafApplication.CreateObjectSpace method.
- Get the object corresponding to the View.CurrentObject using the IObjectSpace.GetObject method.
- Create a new Detail View using the XafApplication.CreateDetailView method and pass it to the CustomizePopupWindowParamsEventArgs.View parameter.
- Optionally, you can customize the Detail View properties (e.g., DetailView.ViewEditMode value).
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Editors;
using DevExpress.Persistent.Base;
//...
public class ShowDetailViewController : ViewController<ListView> {
public ShowDetailViewController() {
PopupWindowShowAction showDetailViewAction = new PopupWindowShowAction(
this, "ShowDetailView", PredefinedCategory.Edit);
showDetailViewAction.SelectionDependencyType = SelectionDependencyType.RequireSingleObject;
showDetailViewAction.TargetObjectsCriteria = "Not IsNewObject(This)";
showDetailViewAction.CustomizePopupWindowParams += showDetailViewAction_CustomizePopupWindowParams;
}
void showDetailViewAction_CustomizePopupWindowParams(
object sender, CustomizePopupWindowParamsEventArgs e) {
IObjectSpace newObjectSpace = Application.CreateObjectSpace(View.ObjectTypeInfo.Type);
Object objectToShow = newObjectSpace.GetObject(View.CurrentObject);
if (objectToShow != null) {
DetailView createdView = Application.CreateDetailView(newObjectSpace, objectToShow);
createdView.ViewEditMode = ViewEditMode.Edit;
e.View = createdView;
}
}
}
In this example, the root Detail View is created using an individual Object Space. The root View contains the Save Action and users can explicitly commit changes. You can customize this behavior using the CreateDetailView method overload with the isRoot parameter, or by providing a nested or existing Object Space instead of a new one. Refer to the View.IsRoot property documentation to learn more.
See Also