学习010-05-02 Text Notifications(文本通知)

Text Notifications(文本通知)

In XAF applications, you can display a message box with a detailed notification text using the ShowViewStrategyBase.ShowMessage method.
在XAF应用程序中,可以使用ShowViewStrategyBase. ShowMessage方法显示包含详细通知文本的消息框。

DevExpress Components and Widgets Used to Show Notifications(用于显示通知的DevExpress组件和小部件)

XAF uses the DevExpress WinForms, DevExtreme, and ASP.NET Core Blazor components and widgets to show the notifications for WinForms, ASP.NET Web Forms, and ASP.NET Core Blazor applications.
XAF使用DevExpress WinForms、DevExtreme和ASP.NETCore Blazor组件和小部件来显示WinForms、ASP.NETWeb Forms和ASP.NETCore Blazor应用程序的通知。

ASP.NET Core Blazor Notifications(ASP.NET核心Blazor通知)

Blazor applications support the following notification API:
Blazor应用程序支持以下通知API:

  • MessageOptions.CancelDelegate
  • MessageOptions.Duration
  • MessageOptions.Message
  • MessageOptions.OkDelegate
  • MessageOptions.Type
  • WebMessageOptions.OkButtonText
  • WebMessageOptions.CssClass
  • WebMessageOptions.ShowCloseButton

Windows Forms Notifications(Windows窗体通知)

You can choose one of the three available notification types listed in the WinMessageType enumeration for a WinForms application:
您可以选择WinForms应用程序的WinMessageType枚举中列出的三种可用通知类型之一:

Alert
The notification is displayed using the Alert Window.
使用警报窗口显示通知。
Toast
The notification window is displayed using the Toast Notification Manager. Used only in Windows 8 or later.
通知窗口使用气泡提示管理器显示。仅在Windows 8或更高版本中使用。
Flyout
The notification window is displayed using the Flyout Dialog.
通知窗口使用弹出对话框显示。

ASP.NET Web Forms Notifications(ASP.NETWeb窗口通知)

Notifications are displayed using the DevExtreme dxToast widget.
使用DevExtreme dxToast小部件显示通知。

Using Text Notifications(使用文本通知)

To display a “Success” message when a user clicks the platform-independent Mark Completed Action, use the ShowMessage(MessageOptions) method. The MessageOptions class contains both the platform-agnostic and platform-specific settings of a text notification.
要在用户单击platform-independent标记已完成操作时显示“成功”消息,请使用ShowMessage(MessageOptions)方法。MessageOptions类包含文本通知的平台无关和平台特定设置。

C# 
using DevExpress.Data.Filtering;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using YourSolutionName.Module.BusinessObjects;


namespace YourSolutionName.Module.Controllers {
    public class DemoTaskController : ViewController {
        public DemoTaskController() {
            TargetObjectType = typeof(DemoTask);
            TargetViewType = ViewType.Any;
            SimpleAction markCompletedAction = new SimpleAction(
                this, "MarkCompleted",
                DevExpress.Persistent.Base.PredefinedCategory.RecordEdit) {
                TargetObjectsCriteria =
                    (CriteriaOperator.Parse("Status != ?", MySolution.Module.BusinessObjects.TaskStatus.Completed)).ToString(),
                ConfirmationMessage =
                            "Are you sure you want to mark the selected task(s) as 'Completed'?",
                ImageName = "State_Task_Completed"
            };
            markCompletedAction.SelectionDependencyType = SelectionDependencyType.RequireMultipleObjects;
            markCompletedAction.Execute += (s, e) => {
                foreach (DemoTask task in e.SelectedObjects) {
                    task.DueDate = DateTime.Now;
                    task.Status = MySolution.Module.BusinessObjects.TaskStatus.Completed;
                    View.ObjectSpace.SetModified(task);
                }
                View.ObjectSpace.CommitChanges();
                View.ObjectSpace.Refresh();
                MessageOptions options = new MessageOptions();
                options.Duration = 2000;
                options.Message = string.Format("{0} task(s) have been successfully updated!", e.SelectedObjects.Count);
                options.Type = InformationType.Success;
                options.Web.Position = InformationPosition.Right;
                options.Win.Caption = "Success";
                options.Win.Type = WinMessageType.Toast;
                options.OkDelegate = () => {
                    IObjectSpace os = Application.CreateObjectSpace(typeof(DemoTask));
                    DetailView newTaskDetailView = Application.CreateDetailView(os, os.CreateObject<DemoTask>());
                    Application.ShowViewStrategy.ShowViewInPopupWindow(newTaskDetailView);
                };
                Application.ShowViewStrategy.ShowMessage(options);
            };
        }
    }
}

ASP.NET Core Blazor
在这里插入图片描述

*Windows Forms
在这里插入图片描述

ASP.NET Web Forms
在这里插入图片描述

Important

  • In Windows Forms applications, the Toast Notifications Manager requires an application shortcut pinned to the Windows 10 start screen to display Toast notifications correctly. Once you do this, you need to customize the ToastNotificationsManager instance as described in the following topic: Toast Notification Manager. Use the CustomizeToastNotificationsManager event to access the instance.
    在Windows窗体应用程序中,Toast通知管理器需要固定到Windows 10开始屏幕的应用程序快捷方式才能正确显示Toast通知。执行此操作后,您需要按照以下主题中的说明自定义ToastNotificationsManager实例:气泡提示管理器。使用CustomizeToastNotificationsManager事件访问实例。
  • In ASP.NET Web Forms applications, notifications can be shown only on postbacks and callbacks initiated by the XAF’s RaiseXafCallback method and processed by XafCallbackManager. This does not work on callbacks initiated by a control, such as a grid sorting callback.
    在ASP.NETWeb窗体应用程序中,通知只能显示在由XAF的RaiseXafCallback方法发起并由XafCallbackManager处理的回发和回调上。这不适用于控件发起的回调,例如网格排序回调。

Notifications Customization(通知定制)

Use the WinMessageOptions.ImageOptions property to change the default image of the WinForms notifications the Toast or Alert control displays:
使用WinMessageOptions. ImageOptions属性更改Toast或Alert控件显示的WinForms通知的默认图像:

  • For the .NET Framework projects:
    对于.NET Framework项目:
C# 
using System.Drawing;
using DevExpress.ExpressApp;
using DevExpress.Utils.Svg;
//...
    MessageOptions options = new MessageOptions();
    //options.Win.ImageOptions.Image = Image.FromFile(@"D:\Images\success.png");
    // or
    options.Win.ImageOptions.SvgImage = SvgImage.FromFile(@"D:\Images\Success.svg");
    options.Win.ImageOptions.SvgImageSize = new Size(50, 50);
    Application.ShowViewStrategy.ShowMessage(options);
  • For .NET projects:
    对于.NET项目:
C# 
using System.Drawing;
using DevExpress.ExpressApp;
using DevExpress.Utils;
using DevExpress.Utils.Svg;
//...
MessageOptions options = new MessageOptions();
ImageOptions imageOptions = new ImageOptions();
//imageOptions.Image = Image.FromFile(@"D:\Images\success.png");
// or
imageOptions.SvgImage = SvgImage.FromFile(@"D:\Images\success.svg");
imageOptions.SvgImageSize = new Size(50, 50);
options.Win.ImageOptions = imageOptions;
Application.ShowViewStrategy.ShowMessage(options);

Alternatively, you can use the WinShowViewStrategyBase class’s CustomGetImage event as shown below:
或者,您可以使用WinShowViewStrategyBase类的CustomGetImage事件,如下所示:

C# 
using System.Drawing;
using DevExpress.ExpressApp.Win;
//...
    ((WinShowViewStrategyBase)Application.ShowViewStrategy).CustomGetImage += 
    ShowMessagesController_CustomGetImage;
    //...
    void ShowMessagesController_CustomGetImage(object sender, CustomGetImageEventArgs e) {
        e.Image = new Bitmap(32, 32); 
        //...
    }
  • Use the WinShowViewStrategyBase class’s CustomGetFlyoutBackColor event to change the Flyout Dialog’s color:
    使用WinShowViewStrategyBase类的CustomGetFlyoutBackColor事件更改跳出对话框的颜色:
C#
using System.Drawing;
using DevExpress.ExpressApp.Win;
//...
    ((WinShowViewStrategyBase)Application.ShowViewStrategy).CustomGetFlyoutBackColor += 
    ShowMessagesController_CustomGetFlyoutBackColor;
    //...
    void ShowMessagesController_CustomGetFlyoutBackColor(object sender, CustomGetFlyoutBackColorEventArgs e) { 
        if(e.InformationType == InformationType.Error) {
            e.BackColor = Color.Red;
        } 
    }
  • Use the WinShowViewStrategyBase class’s CustomizeAlertControl event to customize the Alert control:
    使用WinShowViewStrategyBase类的CustomizeAlertControl事件自定义警报控件:
C# 
using DevExpress.ExpressApp.Utils;
using DevExpress.ExpressApp.Win;
using DevExpress.XtraBars.Alerter;
//...
    ((WinShowViewStrategyBase)Application.ShowViewStrategy).CustomizeAlertControl += 
ShowMessagesController_CustomizeAlertControl;
    //...
    void ShowMessagesController_CustomizeAlertControl(object sender, CustomizeAlertControlEventArgs e) {
        AlertButton button = new AlertButton(ImageLoader.Instance.GetImageInfo("BO_Attention").Image);
        button.Name = "buttonAlert";
        e.AlertControl.Buttons.Add(button);
        //...
    }
  • Use the WinShowViewStrategyBase class’s CustomizeToastNotificationsManager to access the Toast Notification Manager instance:
    使用WinShowViewStrategyBase类的CustomizeToastNotificationsManager访问气泡提示管理器实例:
C#
using DevExpress.ExpressApp.Win;
//...
    ((WinShowViewStrategyBase)Application.ShowViewStrategy).CustomizeToastNotificationsManager +=
ShowMessagesController_CustomizeToastNotificationsManager;
    //...
    void ShowMessagesController_CustomizeToastNotificationsManager(object sender, 
CustomizeToastNotificationsManagerEventArgs e) {
        e.ToastNotificationsManager.UserCancelled += ToastNotificationsManager_UserCancelled;
    }
    void ToastNotificationsManager_UserCancelled(object sender, 
DevExpress.XtraBars.ToastNotifications.ToastNotificationEventArgs e) {
        //...
    }

Notification Button Caption Localization(通知按钮字幕本地化)

You can localize the notification button captions using the Model Editor. Navigate to the Localization | DialogButtons node, choose the OK or Cancel node and set a particular string to the Value property. Note that this setting also applies to other dialog buttons.
您可以使用模型编辑器本地化通知按钮标题。导航到本地化|对话框按钮节点,选择确定或取消节点,并将特定字符串设置为值属性。请注意,此设置也适用于其他对话框按钮。

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

汤姆•猫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值