Skip to main content

Dialog Controller

  • 6 minutes to read

The XAF has several Controllers that are automatically added to each Frame and provide basic functionality in applications (NewObjectViewController, ShowNavigationItemController, etc.). However, this does not include the DialogController- you need to add it manually if it is required. It is used to add the Accept and Cancel buttons in pop-up Windows. For instance, the Dialog Controller is contained in the pop-up Window that is invoked by a PopupWindowShowAction. This Controller provides the OK and Cancel buttons. This topic describes the Dialog Controller’s behavior and how to use it in a pop-up Window.

Dialog Controller Overview

The DialogController is inherited from the WindowController class. It contains the following Actions:

Action

Description

Accept Action

Specified by the DialogController.AcceptAction property. If the current pop-up Window contains a Detail View, this Action executes the Save Action of the Window’s ModificationsController. You can cancel saving by setting the DialogController.SaveOnAccept property to false. This action has no effect if the current pop-up Window contains a List View. To implement custom code before executing the default code associated with this Action, handle the DialogController.Accepting event.

The pop-up Window is closed after executing the Accept Action by default. To cancel closing, set the DialogController.CanCloseWindow parameter to false.

Cancel Action

Specified by the DialogController.CancelAction property. This Action closes the current pop-up Window by default. To implement custom code before closing the Window, handle the DialogController.Cancelling event. You can also cancel closing the Window by setting the DialogController.CanCloseWindow property to false.

Close Action

This Action is not displayed in a pop-up Window because the Template that represents the Window does not contain the Action Container associated with the Action. However, this Action is executed when pressing a selected row in the pop-up Window’s List View. This Action’s ExecuteCompleted event is handled by the corresponding event handler of the Accept Action, which closes the pop-up window.

The Dialog Controller has the following specificities:

Read the sections below for details on how to use Dialog Controllers in pop-up Windows that are invoked after executing an Action, and in pop-up Windows invoked via PopupWindowShowAction (see Ways to Show a View).

Dialog Controllers in Pop-up Windows Invoked via ShowViewParameters Objects

To invoke a Window after an Action is executed, specify an ActionBaseEventArgs.ShowViewParameters parameter of the Action’s Execute event handler. The following conditions should be satisfied to create the invoked Window pop-up application:

Note

For information on which templates are created for each template context and how to customize them on different platforms, refer to the following topic: Templates.

To add a Dialog Controller to the pop-up window, use the ShowViewParameters.Controllers parameter of the Action’s Execute event handler. The following code demonstrates how to create a List View in a pop-up window and add a Dialog Controller:

using DevExpress.ExpressApp.SystemModule;
// ...
void myAction_Execute(Object sender, SimpleActionExecuteEventArgs e) {
   IObjectSpace objectSpace = Application.CreateObjectSpace(typeof(MyBusinessClass));
   string listViewId = Application.FindListViewId(typeof(MyBusinessClass));
   e.ShowViewParameters.CreatedView = Application.CreateListView(
      listViewId,
      Application.CreateCollectionSource(objectSpace, typeof(MyBusinessClass), listViewId),
      true);
   e.ShowViewParameters.TargetWindow = TargetWindow.NewWindow;
   e.ShowViewParameters.Context = TemplateContext.PopupWindow;
   e.ShowViewParameters.Controllers.Add(Application.CreateController<DialogController>());
}

Note

  • You can add the built-in DialogController or a custom one that is inherited from it.
  • If the ShowViewParameters.CreateAllControllers property is set to false and you want the Actions’ buttons in a Template, add the FillActionContainersController to the Controllers collection.

Dialog Controllers in Pop-up Windows Invoked via PopupWindowShowAction Type Actions

The pop-up Windows which are invoked when pressing a Pop-up Window Show Action contain a DialogController type Dialog Controller. You can change the behavior of the Dialog Controller’s Actions as follows:

Action

Description

Accept Action

Called “OK” by default. To set another caption, use the PopupWindowShowAction.AcceptButtonCaption property.

This raises the ActionBase.Executing, PopupWindowShowAction.Execute and ActionBase.Executed events, sequentially. Then, if the PopupWindowShowActionExecuteEventArgs.CanCloseWindow parameter of the Execute event handler is set to true, it saves the changes (if the Window contains a Detail View), and closes the Window. Otherwise, it does nothing.

Cancel Action

Called “Cancel” by default. To set another caption, use the PopupWindowShowAction.CancelButtonCaption property.

The PopupWindowShowAction.Cancel event is raised when an end user clicks the current pop-up Window’s Cancel button (see the table above).

You can use the PopupWindowShowAction.CustomizePopupWindowParams event handler’s CustomizePopupWindowParamsEventArgs.DialogController parameter to customize the default Dialog Controller the pop-up Window uses. You can also replace this Dialog Controller with a custom one. The code below demonstrates creating a List View in a Pop-up Window and adding a custom Dialog Controller.

private void MyPopupWindowShowAction_CustomizePopupWindowParams(object sender, 
      CustomizePopupWindowParamsEventArgs e) {
   IObjectSpace objectSpace = Application.CreateObjectSpace(typeof(MyBusinessClass));
   string listViewId = Application.FindListViewId(typeof(MyBusinessClass));
   e.View =  Application.CreateListView(
      listViewId,
      Application.CreateCollectionSource(objectSpace, typeof(MyBusinessClass), listViewId),
      true);
   e.DialogController = Application.CreateController<MyDialogController>();
}