DialogService
允许您显示对话框。
接口
IDialogService
托管控件
- XtraForm
- FlyoutDialog
- RibbonForm
全局注册
C#
MVVMContext.RegisterXtraDialogService();MVVMContext.RegisterFlyoutDialogService();MVVMContext.RegisterRibbonDialogService();
VB.NET
MVVMContext.RegisterXtraDialogService()MVVMContext.RegisterFlyoutDialogService()MVVMContext.RegisterRibbonDialogService()
DevExpress MVVM 框架自动调用 RegisterXtraDialogService 方法。
本地注册
C#
mvvmContext1.RegisterService(DialogService.CreateXtraDialogService(this));mvvmContext1.RegisterService(DialogService.CreateFlyoutDialogService(this));mvvmContext1.RegisterService(DialogService.CreateRibbonDialogService(this));mvvmContext1.RegisterService(DialogService.Create(this, DefaultDialogServiceType.RibbonDialog));
VB.NET
mvvmContext1.RegisterService(DialogService.CreateXtraDialogService(Me))mvvmContext1.RegisterService(DialogService.CreateFlyoutDialogService(Me))mvvmContext1.RegisterService(DialogService.CreateRibbonDialogService(Me))mvvmContext1.RegisterService(DialogService.Create(Me, DefaultDialogServiceType.RibbonDialog))
Create() 方法
DialogService 的所有‘Create…’方法都需要一个拥有该服务的视图,如果您传递 null 而不是 View,框架会尝试定位适当的窗口(在大多数情况下,使用激活窗口)。
- Create(IWin32Window owner, DefaultDialogServiceType type) – 使用 DefaultDialogServiceType 枚举器值来确定要创建的服务类型。
- CreateXtraDialogService(IWin32Window owner) – 创建一个显示skinnable DevExpress 对话框的服务。
- CreateFlyoutDialogService(IWin32Window owner) – 创建一个显示FlyoutDialog 的服务。
- CreateRibbonDialogService(IWin32Window owner) – 创建一个将带有嵌入式RibbonControls的RibbonForms 显示为对话框的服务,对话框按钮显示为功能区项目。
- Create(IWin32Window owner, string title, Func<IDialogForm> factoryMethod) – 允许您注册管理自定义对话框(实现 IDialogForm 接口的对象)的服务。
C#
DialogService.Create(ownerView1, "A custom dialog", ()=> new CustomDialogClass());
VB.NET
DialogService.Create(ownerView1, "A custom dialog", Function() New CustomDialogClass())
- DialogService Create(IWin32Window owner, string title, IDialogFormFactory factory) – 接受创建自定义对话框的工厂类。
公共服务方法
- ShowDialog – 六个扩展方法,显示具有特定外观和内容的对话框。
C#
public void FindCustomer() {if(DialogService.ShowDialog(MessageButton.OKCancel, "Find Customer", findDialogViewModel) == MessageResult.OK) {// do something}}
VB.NET
Public Sub FindCustomer()If DialogService.ShowDialog(MessageButton.OKCancel, "Find Customer", findDialogViewModel) = MessageResult.OK Then' do somethingEnd IfEnd Sub
这些重载允许您用自定义 UICommand 对象替换默认对话框按钮。 为此,请将自定义命令的 Id 或 Tag 属性用作 MessageResult 或 DialogResult 值。
C#
public void FindCustomer() {var findDialogViewModel = FindDialogViewModel.Create();findDialogViewModel.SetParentViewModel(this);var commands = new List<UICommand>{// Button with custom command attachednew UICommand {Id = "Find",Caption = "Find",Command = new DelegateCommand(() =>{// . . . implement the Find command here}),IsDefault = true,IsCancel = false,Tag = DialogResult.OK},// standard button caption customizationnew UICommand {Caption = "Cancel Find",Tag = DialogResult.Cancel}};DialogService.ShowDialog(commands, "Find Customer", "FindDialogView", SelectedEntity, findDialogViewModel);}
VB.NET
Public Sub FindCustomer()Dim findDialogViewModel = FindDialogViewModel.Create()findDialogViewModel.SetParentViewModel(Me)Dim commands = New List(Of UICommand) From {New UICommand With {.Id = "Find", .Caption = "Find", .Command = New DelegateCommand(Sub()End Sub), .IsDefault = True, .IsCancel = False, .Tag = DialogResult.OK},New UICommand With {.Caption = "Cancel Find", .Tag = DialogResult.Cancel}}DialogService.ShowDialog(commands, "Find Customer", "FindDialogView", SelectedEntity, findDialogViewModel)End Sub
- DialogFormStyle – 允许您访问对话框并修改其外观设置。 例如,下面的代码说明了如何将粗体字体样式应用于弹出对话框按钮。
C#
var service = DialogService.CreateFlyoutDialogService(this);service.DialogFormStyle = (form) =>{FlyoutDialog dialog = form as FlyoutDialog;dialog.Properties.AppearanceButtons.FontStyleDelta = FontStyle.Bold;};
VB.NET
Dim service = DialogService.CreateFlyoutDialogService(Me)service.DialogFormStyle = Sub(form)Dim dialog As FlyoutDialog = TryCast(form, FlyoutDialog)dialog.Properties.AppearanceButtons.FontStyleDelta = FontStyle.BoldEnd Sub
DevExpress WinForm | 下载试用
DevExpress WinForm拥有180+组件和UI库,能为Windows Forms平台创建具有影响力的业务解决方案。DevExpress WinForms能完美构建流畅、美观且易于使用的应用程序,无论是Office风格的界面,还是分析处理大批量的业务数据,它都能轻松胜任!
更多产品正版授权详情及优惠,欢迎咨询在线客服>>
DevExpress技术交流群5:742234706 欢迎一起进群讨论
DevExpress线上公开课主题票选火热开启,主题由你来定!点击填写问卷

标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!