UI组件DevExpress WinForm入门指南 - DialogService服务 DevExpressWinFormUI组件c# winform
程序员文章站
2022-02-19 06:35:30
...
DevExpress Services将命令从ViewModel传递到View中的控件,这允许您在不分离应用程序层的情况下修改 UI。
DialogService
允许您显示对话框。
接口
托管控件
全局注册
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 something End If End 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 attached new UICommand { Id = "Find", Caption = "Find", Command = new DelegateCommand(() =>{ // . . . implement the Find command here }), IsDefault = true, IsCancel = false, Tag = DialogResult.OK }, // standard button caption customization new 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.Bold End Sub
DevExpress WinForm拥有180+组件和UI库,能为Windows Forms平台创建具有影响力的业务解决方案。DevExpress WinForms能完美构建流畅、美观且易于使用的应用程序,无论是Office风格的界面,还是分析处理大批量的业务数据,它都能轻松胜任!
DevExpress技术交流群5:742234706 欢迎一起进群讨论
DevExpress线上公开课主题票选火热开启,主题由你来定!点击填写问卷