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 allows you to show a Detail View of the List View’s selected object in a pop-up window.
To do this, follow the steps below:
- Create a View Controller with the PopupWindowShowAction.
- Handle the Action’s PopupWindowShowAction.CustomizePopupWindowParams event.
- In the event handler, use the XafApplication.CreateObjectSpace method to create an Object Space.
- Use the IObjectSpace.GetObject method to get the View.CurrentObject object from the
IObjectSpace
created at the previous step. - 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 (for example, 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; } } }
After you run the code above:
XAF adds a new Show Detail View Action to a List View toolbar. This Action requires a user to select a single object in a List View (for more information, refer to the following topic: SelectionDependencyType.RequireSingleObject).
When a user clicks this Action, the application opens a Detail View for the selected object in a pop-up window.
The pop-up window uses a separate Object Space and displays the Save Action that allows users to explicitly commit changes. You can use any of the following options to customize this behavior:
- Call the
CreateDetailView
method overload with theisRoot
parameter. - Access a nested or existing Object Space instead of a new one.
For more information, refer to the View.IsRoot property documentation.
- Call the