繁体   English   中英

在 Caliburn.Micro、WPF 中单击时阻止 UI

[英]Blocking UI on click in Caliburn.Micro, WPF

如何在Caliburn.Micro阻止 UI?

public async void AcceptButton()
{
    await this.httpDataService.Register(account);
    Show.SuccesBox(alert);
    this.TryClose();
}

如何通过阻止View来等待ViewModelTask结束?

编辑

我在xaml按钮上添加了绑定:

 IsEnabled="{Binding isEnabled}"

然后,我的VM

bool isEnabled {get;set;}

public async void AcceptButton()
{
    this.isEnabled = false;
    await this.httpDataService.Register(account);
    Show.SuccesBox(alert);
    this.TryClose();
}

在这种情况下, AcceptButton始终处于非活动状态IsEnabled=false 如何仅在单击按钮时触发false

因为我不想用户双击“发送表单”按钮

这样做的标准方法就是禁用按钮。 或者,如果要禁用整个表单,则禁用整个窗口:

public async void AcceptButton()
{
  this.IsEnabled = false;
  await this.httpDataService.Register(account);
  Show.SuccesBox(alert);
  this.TryClose();
}

您应该将IsEnabled属性添加到您的视图模型类,然后将其绑定到视图的IsEnabled属性。

与无响应的应用程序相比,禁用窗口对用户来说更好,因为这种方法允许用户将其最小化或在意外花费很长时间时将其移开。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM