DevExpress控件使用交流,DevExpress中国社区Dev联系电话 联系电话:023-68661681

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

来源:   发布时间:2022-01-24   浏览:1149次

DevExpress Services将命令从ViewModel传递到View中的控件,这允许您在不分离应用程序层的情况下修改 UI。

获取工具下载 - DevExpress v21.2

可用服务
  • 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 registration
MVVMContext.RegisterMessageBoxService();
//1. Local registration
mvvmContext1.RegisterService(CreateXtraMessageBoxService());

//2. POCO ViewModel property that returns a Service
protected virtual IMessageBoxService MessageBoxService {
get { throw new System.NotImplementedException(); }
}

//3. Send a Service command to a View
public void SayHello() {
MessageBoxService.Show("Hello!");
}

VB.NET

'1. Global registration
MVVMContext.RegisterMessageBoxService()
'1. Local registration
mvvmContext1.RegisterService(CreateXtraMessageBoxService())

'2. POCO ViewModel property that returns a Service
protected virtual IMessageBoxService MessageBoxService
Get
Throw New System.NotImplementedException()
End Get

'3. Send a Service command to a View
public void SayHello()
MessageBoxService.Show("Hello!")
MessageBoxService

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

接口

IMessageBoxService

托管控件

全局注册

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.Bold
End Sub

DevExpress WinForm | 下载试用

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

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


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

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

DevExpress企业定制服务
本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/2868.html

相关产品: DevExpress Universal Subscription,

在线
客服
微信
QQ 电话
023-68661681
返回
顶部