DevExpress Services将命令从ViewModel传递到View中的控件,这允许您在不分离应用程序层的情况下修改 UI。
获取工具下载 - DevExpress v21.2
DialogService
允许您显示对话框。
接口
IDialogService
托管控件
全局注册
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,框架会尝试定位适当的窗口(在大多数情况下,使用激活窗口)。
C#
DialogService.Create(ownerView1, "A custom dialog", ()=> new CustomDialogClass());
VB.NET
DialogService.Create(ownerView1, "A custom dialog", Function() New CustomDialogClass())
公共服务方法
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
{
// 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
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 | 下载试用
DevExpress WinForm拥有180+组件和UI库,能为Windows Forms平台创建具有影响力的业务解决方案。DevExpress WinForms能完美构建流畅、美观且易于使用的应用程序,无论是Office风格的界面,还是分析处理大批量的业务数据,它都能轻松胜任!
DevExpress技术交流群5:742234706 欢迎一起进群讨论
DevExpress线上公开课主题票选火热开启,主题由你来定!点击填写问卷