DevExpress WinForm控件入门指南:标准DevExpress服务 – MessageBoxService

本文主要介绍如何使用标准DevExpress服务及MessageBoxService,欢迎下载最新版体验!

可用服务
  • MessageBoxService
  • DialogService
  • Current Dialog Service
  • CurrentWindowService
  • Window Service
  • DocumentManagerService
  • WindowedDocumentManagerService
  • NavigationService
  • DispatcherService
  • Notification Service
  • SplashScreen Service
  • Open and Save File Dialog Services
  • Folder Browser Dialog Service
如何使用服务
  1. 注册服务。
    • 本地注册(Service 仅在 View 中可用):调用 mvvmContext1.RegisterService 方法并将 Service 的 Create 方法之一作为参数传递,DevExpress MVVM 框架自动注册最常用的服务。
    • 全局注册(整个应用可用的Service):调用对应的静态MVVMContext.Register…Service方法。
  2. 定义一个 ViewModel 属性,该属性返回相关 Service 接口的对象(例如,如果您注册了 WindowedDocumentManagerService,您的属性应该是 IDocumentManagerService 类型)。
  3. 使用此属性访问服务并调用服务方法将命令发送到视图。

示例

C#

//1. Global registrationMVVMContext.RegisterMessageBoxService();//1. Local registrationmvvmContext1.RegisterService(CreateXtraMessageBoxService());//2. POCO ViewModel property that returns a Serviceprotected virtual IMessageBoxService MessageBoxService {get { throw new System.NotImplementedException(); }}//3. Send a Service command to a Viewpublic void SayHello() {MessageBoxService.Show("Hello!");}

VB.NET

'1. Global registrationMVVMContext.RegisterMessageBoxService()'1. Local registrationmvvmContext1.RegisterService(CreateXtraMessageBoxService())'2. POCO ViewModel property that returns a Serviceprotected virtual IMessageBoxService MessageBoxServiceGetThrow New System.NotImplementedException()End Get'3. Send a Service command to a Viewpublic void SayHello()MessageBoxService.Show("Hello!")
MessageBoxService

允许您显示消息框和浮出控件。

接口

IMessageBoxService

托管控件

  • System.Windows.Forms.MessageBox
  • XtraMessageBox
  • FlyoutDialog

全局注册

C#

MVVMContext.RegisterMessageBoxService();MVVMContext.RegisterXtraMessageBoxService();MVVMContext.RegisterFlyoutMessageBoxService();

VB.NET

MVVMContext.RegisterMessageBoxService()MVVMContext.RegisterXtraMessageBoxService()MVVMContext.RegisterFlyoutMessageBoxService()

DevExpress MVVM 框架自动调用 RegisterXtraMessageBoxService 方法。

本地注册

C#

mvvmContext1.RegisterService(//one of "Create" methods from the list below);

VB.NET

mvvmContext1.RegisterService('one of "Create" methods from the list below)

Create() 方法

  • Create(DefaultMessageBoxServiceType type) – 使用 DefaultMessageBoxServiceType 枚举值来确定要创建的服务类型。
  • CreateMessageBoxService() – 创建一个使用标准 WinForms 消息框的服务。
  • CreateXtraMessageBoxService() – 创建一个使用 DevExpress XtraMessageBox 对象的服务。
  • CreateFlyoutMessageBoxService() – 创建一个使用 FlyoutDialog 对象的服务。

所有四个方法都具有与第二个 IWin32Window 所有者参数对应的重载,此参数允许您指定拥有此服务的视图。 如果您传递 null 而不是 owner 参数,则框架会尝试找到应该是服务所有者的适当视图。 在大多数情况下,使用激活窗口。

公共服务成员

  • ShowMessage – 显示消息框的五种扩展方法。
  • MessageBoxFormStyle – 允许您访问消息框表单并修改其外观设置。 例如,下面的代码说明了如何将粗体字体样式应用于消息框按钮。

C#

var msgService = MessageBoxService.CreateFlyoutMessageBoxService();msgService.MessageBoxFormStyle = (form) => {{FlyoutDialog msgFrm = form as FlyoutDialog;msgFrm.Properties.AppearanceButtons.FontStyleDelta = FontStyle.Bold;};

VB.NET

Dim msgService = MessageBoxService.CreateFlyoutMessageBoxService(Me)msgService.DialogFormStyle = Sub(form)Dim msgFrm As FlyoutDialog = TryCast(form, FlyoutDialog)msgFrm.Properties.AppearanceButtons.FontStyleDelta = FontStyle.BoldEnd Sub

DevExpress WinForm | 下载试用

DevExpress WinForm拥有180+组件和UI库,能为Windows Forms平台创建具有影响力的业务解决方案。DevExpress WinForms能完美构建流畅、美观且易于使用的应用程序,无论是Office风格的界面,还是分析处理大批量的业务数据,它都能轻松胜任!

更多产品正版授权详情及优惠,欢迎咨询在线客服>>


DevExpress技术交流群5:742234706      欢迎一起进群讨论

DevExpress线上公开课主题票选火热开启,主题由你来定!点击填写问卷

DevExpress企业定制服务
标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2022年1月20日
下一篇 2022年1月20日

相关推荐

发表回复

登录后才能评论