Skip to main content
A newer version of this page is available. .

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:

  1. Create a View Controller with the PopupWindowShowAction.
  2. Handle the Action’s PopupWindowShowAction.CustomizePopupWindowParams event.
  3. In the event handler, use the XafApplication.CreateObjectSpace method to create an Object Space.
  4. Use the IObjectSpace.GetObject method to get the View.CurrentObject object from the IObjectSpace created at the previous step.
  5. Create a new Detail View using the XafApplication.CreateDetailView method and pass it to the CustomizePopupWindowParamsEventArgs.View parameter.
  6. 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:

  1. 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).

  2. When a user clicks this Action, the application opens a Detail View for the selected object in a pop-up window.

    DevExpress XAF: Show a Detail View of the Selected Object in a Popup Window

  3. 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 the isRoot parameter.
    • Access a nested or existing Object Space instead of a new one.

    For more information, refer to the View.IsRoot property documentation.

See Also