翻譯|使用教程|編輯:龔雪|2022-02-09 10:02:55.577|閱讀 295 次
概述:本文主要介紹如何使用標準DevExpress服務的DialogService,歡迎下載最新版體驗!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
DevExpress Services將命令從ViewModel傳遞到View中的控件,這允許您在不分離應用程序層的情況下修改 UI。
允許您顯示對話框。
接口
托管控件
全局注冊
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<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
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 歡迎一起進群討論
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都網