From 40efe5292fbdceeefc912c75eaa2e63351ecc1ff Mon Sep 17 00:00:00 2001 From: luxiaoqi Date: Thu, 23 Nov 2023 09:57:32 +0800 Subject: [PATCH] 1 --- CPF.Toolkit.Demo/MainView.cs | 5 ----- CPF.Toolkit.Demo/MainViewModel.cs | 12 +++++++++++- CPF.Toolkit/Dialogs/DialogView.cs | 4 ++-- CPF.Toolkit/ViewModelBase.cs | 11 +++++++---- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/CPF.Toolkit.Demo/MainView.cs b/CPF.Toolkit.Demo/MainView.cs index b385519..84817ed 100644 --- a/CPF.Toolkit.Demo/MainView.cs +++ b/CPF.Toolkit.Demo/MainView.cs @@ -66,11 +66,6 @@ namespace CPF.Toolkit.Demo Commands = { { nameof(Button.Click),(s,e) => vm.Test() } } }, new Button - { - Content = "关闭窗体", - Commands = { { nameof(Button.Click),(s,e) => vm.Test() } } - }, - new Button { Content = "loading", Commands = { { nameof(Button.Click),(s,e) => vm.LoadingTest() } } diff --git a/CPF.Toolkit.Demo/MainViewModel.cs b/CPF.Toolkit.Demo/MainViewModel.cs index efe9c4d..f38b421 100644 --- a/CPF.Toolkit.Demo/MainViewModel.cs +++ b/CPF.Toolkit.Demo/MainViewModel.cs @@ -1,6 +1,7 @@ using CPF.Controls; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -27,7 +28,16 @@ namespace CPF.Toolkit.Demo public async void LoadingTest() { - await this.ShowLoading(Task.Delay(3000)); + await this.ShowLoading(async () => + { + await Task.Delay(1000); + Debug.WriteLine(1); + await Task.Delay(1000); + Debug.WriteLine(2); + await Task.Delay(1000); + Debug.WriteLine(3); + }); + //await this.ShowLoading(Task.Delay(3000)); this.Dialog.Sucess("test"); //var result = await this.ShowLoading(async () => diff --git a/CPF.Toolkit/Dialogs/DialogView.cs b/CPF.Toolkit/Dialogs/DialogView.cs index 8a752b0..beb4ec4 100644 --- a/CPF.Toolkit/Dialogs/DialogView.cs +++ b/CPF.Toolkit/Dialogs/DialogView.cs @@ -14,7 +14,7 @@ using System.Text; namespace CPF.Toolkit.Dialogs { - public class DialogView : Window + internal class DialogView : Window { public DialogView(string text, string title, DialogType dialogType, string defaultButton, params string[] buttons) { @@ -112,7 +112,7 @@ namespace CPF.Toolkit.Dialogs BorderFill = "236,236,236", Height = "95%", MarginRight = 5, - Commands = { { nameof(Button.Click),(s,e) => this.DialogResult = i } } + Commands = { { nameof(Button.Click),(s,e) => this.DialogResult = this.Buttons[i] } } }), } })); diff --git a/CPF.Toolkit/ViewModelBase.cs b/CPF.Toolkit/ViewModelBase.cs index 34a2d2b..0688165 100644 --- a/CPF.Toolkit/ViewModelBase.cs +++ b/CPF.Toolkit/ViewModelBase.cs @@ -22,10 +22,7 @@ namespace CPF.Toolkit protected void Close(object dialogResult = null) { - if (this._close == null) - { - throw new ArgumentNullException(); - } + if (this._close == null) throw new ArgumentNullException(); this._close.Invoke(this, dialogResult); } @@ -37,6 +34,12 @@ namespace CPF.Toolkit await this._showLading.Invoke("加载中……", task); } + protected async Task ShowLoading(Func task) + { + if (this._showLoadingFunc == null) throw new ArgumentNullException(); + await this._showLading.Invoke("加载中……", task.Invoke()); + } + protected async Task ShowLoading(Func> task) { if (this._showLoadingFunc == null) throw new ArgumentNullException();