简体   繁体   English

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

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

How to block UI in Caliburn.Micro ?如何在Caliburn.Micro阻止 UI?

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

How to wait for end of Task in my ViewModel by blocking View ?如何通过阻止View来等待ViewModelTask结束?

EDIT编辑

i added binding on my button in xaml :我在xaml按钮上添加了绑定:

 IsEnabled="{Binding isEnabled}"

Then, my VM :然后,我的VM

bool isEnabled {get;set;}

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

In this case, AcceptButton is always unactive IsEnabled=false .在这种情况下, AcceptButton始终处于非活动状态IsEnabled=false How to trigger false only on button click?如何仅在单击按钮时触发false

because i dont want to user double-tap "Send form" button因为我不想用户双击“发送表单”按钮

The standard way of doing that is just disabling the button.这样做的标准方法就是禁用按钮。 Or, if you want to disable the entire form, then disable the entire window:或者,如果要禁用整个表单,则禁用整个窗口:

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

You should add the IsEnabled property to your view model class and then bind it to the IsEnabled property of the view.您应该将IsEnabled属性添加到您的视图模型类,然后将其绑定到视图的IsEnabled属性。

Disabling the window is nicer to the user than an unresponsive application, because this approach allows the user to minimize it or move it out of the way if it is taking an unexpectedly long time.与无响应的应用程序相比,禁用窗口对用户来说更好,因为这种方法允许用户将其最小化或在意外花费很长时间时将其移开。

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

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