expressappframework-401750-ui-construction-views-asynchronous-data-loading-how-to-customize-asynchronous-data-loading-behavior-and-ui.md
This topic describes how to use the built-in AsyncLoadingCancelationController and AsyncLoadingIndicationController to customize asynchronous data loading in your WinForms application.
In the Program.cs file, set the static ShowConfirmationDefault field of the AsyncLoadingCancelationController to true.
using System;
using DevExpress.ExpressApp.Win.SystemModule;
// ...
public class Program {
[STAThread]
public static void Main(string[] arguments) {
AsyncLoadingCancelationController.ShowConfirmationDefault = true;
// ...
}
// ...
}
OnActivated method, use the GetController<ControllerType>() method to access the AsyncLoadingCancelationController.AsyncLoadingCancelationController‘s ShowConfirmation property to true.using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Win.SystemModule;
// ...
public class EnableConfirmationController : ObjectViewController<ListView, Contact> {
protected override void OnActivated() {
base.OnActivated();
AsyncLoadingCancelationController controller = Frame.GetController<AsyncLoadingCancelationController>();
if (controller != null) {
controller.ShowConfirmation = true;
}
}
}
The following image demonstrates the default confirmation message displayed when a user cancels data loading.
To change the confirmation message text, open the Model Editor, navigate to the Localization | Confirmations | ConfirmCancelAsyncOperation node, and change its Value.
XAF disables all built-in Actions except Close to prevent manipulations of the current View’s data. It is recommended that you disable custom Actions while View data is loading asynchronously.
AsyncLoadingIndicationController‘s descendant in the WinForms application project (MySolution.Win).UpdateActions protected method.AsyncLoadingIndicationController.UpdateAction method.using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Win.SystemModule;
// ...
public class UpdateCustomActionsOnAsyncLoadingController : AsyncLoadingIndicationController {
protected override void UpdateActions(bool isEnabled) {
base.UpdateActions(isEnabled);
UpdateAction(Frame.GetController<CustomActionController>()?.CustomAction, isEnabled);
}
}
The image below demonstrates how this Controller affects the UI.
You can implement custom logic when an application starts or stops loading data. For example, you can display text notifications, as shown below.
AsyncLoadingIndicationController‘s descendant in the WinForms application project (MySolution.Win).StartLoading and **StopLoading protected methods.using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Win.SystemModule;
using System.Windows.Forms;
// ...
public class CustomAsyncLoadingIndicationController : AsyncLoadingIndicationController {
private void ShowMessage(string message, string caption, InformationType informationType) {
MessageOptions options = new MessageOptions();
options.Duration = 2000;
options.Message = string.Format(message);
options.Type = informationType;
options.Win.Caption = caption;
options.Win.Type = WinMessageType.Alert;
Application.ShowViewStrategy.ShowMessage(options);
}
protected override void StopLoading() {
base.StopLoading();
ShowMessage("Operation completed", "Stop loading", InformationType.Info);
}
protected override void StartLoading(Control control) {
base.StartLoading(control);
ShowMessage("Data is loading", "Start loading", InformationType.Info);
}
}
The following image shows the result.