This commit is contained in:
luxiaoqi 2023-11-23 09:57:32 +08:00
parent 313f8fd79b
commit 40efe5292f
4 changed files with 20 additions and 12 deletions

View File

@ -66,11 +66,6 @@ namespace CPF.Toolkit.Demo
Commands = { { nameof(Button.Click),(s,e) => vm.Test() } } Commands = { { nameof(Button.Click),(s,e) => vm.Test() } }
}, },
new Button new Button
{
Content = "关闭窗体",
Commands = { { nameof(Button.Click),(s,e) => vm.Test() } }
},
new Button
{ {
Content = "loading", Content = "loading",
Commands = { { nameof(Button.Click),(s,e) => vm.LoadingTest() } } Commands = { { nameof(Button.Click),(s,e) => vm.LoadingTest() } }

View File

@ -1,6 +1,7 @@
using CPF.Controls; using CPF.Controls;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -27,7 +28,16 @@ namespace CPF.Toolkit.Demo
public async void LoadingTest() 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"); this.Dialog.Sucess("test");
//var result = await this.ShowLoading(async () => //var result = await this.ShowLoading(async () =>

View File

@ -14,7 +14,7 @@ using System.Text;
namespace CPF.Toolkit.Dialogs 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) 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", BorderFill = "236,236,236",
Height = "95%", Height = "95%",
MarginRight = 5, MarginRight = 5,
Commands = { { nameof(Button.Click),(s,e) => this.DialogResult = i } } Commands = { { nameof(Button.Click),(s,e) => this.DialogResult = this.Buttons[i] } }
}), }),
} }
})); }));

View File

@ -22,10 +22,7 @@ namespace CPF.Toolkit
protected void Close(object dialogResult = null) protected void Close(object dialogResult = null)
{ {
if (this._close == null) if (this._close == null) throw new ArgumentNullException();
{
throw new ArgumentNullException();
}
this._close.Invoke(this, dialogResult); this._close.Invoke(this, dialogResult);
} }
@ -37,6 +34,12 @@ namespace CPF.Toolkit
await this._showLading.Invoke("加载中……", task); await this._showLading.Invoke("加载中……", task);
} }
protected async Task ShowLoading(Func<Task> task)
{
if (this._showLoadingFunc == null) throw new ArgumentNullException();
await this._showLading.Invoke("加载中……", task.Invoke());
}
protected async Task<T> ShowLoading<T>(Func<Task<T>> task) protected async Task<T> ShowLoading<T>(Func<Task<T>> task)
{ {
if (this._showLoadingFunc == null) throw new ArgumentNullException(); if (this._showLoadingFunc == null) throw new ArgumentNullException();