CPF/CPF.Toolkit/Controls/AsyncButton.cs
luxiaoqi 8decf9e554 1
2023-11-23 13:38:29 +08:00

32 lines
777 B
C#

using CPF.Controls;
using CPF.Toolkit.Input;
using System;
using System.Collections.Generic;
using System.Text;
namespace CPF.Toolkit.Controls
{
public class AsyncButton : Button
{
protected override void InitializeComponent()
{
base.InitializeComponent();
this.Triggers.Add(nameof(IsEnabled), Relation.Me, null, (nameof(Background), "224,224,224"));
}
public IAsyncCommand Command { get; set; }
protected override async void OnClick(RoutedEventArgs e)
{
this.IsEnabled = false;
base.OnClick(e);
if (this.Command != null)
{
await this.Command.ExecuteAsync();
}
this.IsEnabled = true;
}
}
}