C# 在Caliburn.Micro、WPF中单击时阻止UI
如何在Caliburn.Micro中阻止UIC# 在Caliburn.Micro、WPF中单击时阻止UI,c#,wpf,task,caliburn.micro,C#,Wpf,Task,Caliburn.micro,如何在Caliburn.Micro中阻止UI public async void AcceptButton() { await this.httpDataService.Register(account); Show.SuccesBox(alert); this.TryClose(); } 如何在myViewModel中通过阻止View来等待任务的结束 编辑 我在xaml中的按钮上添加了绑定: IsEnabled="{Binding isEnabled}" 然后,我
public async void AcceptButton()
{
await this.httpDataService.Register(account);
Show.SuccesBox(alert);
this.TryClose();
}
如何在myViewModel
中通过阻止View
来等待任务的结束
编辑
我在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
属性
禁用窗口对用户来说比无响应的应用程序更好,因为这种方法允许用户最小化窗口,或者在花费意外的长时间时将其移开。是否要阻止用户在运行过程中执行任何其他操作?是的,我要阻止整个应用程序“如何阻止UI”-正确的答案是“你不想。”你为什么要这样做?谢谢你的反馈,但是我在我的帖子中提到了
Caliburn.Micro
,因为我使用这个框架来表达我的观点。正因为如此,我不能像你提到的那样阻止我的按钮,因为IsEnabled
在caliburn中没有定义;sViewModels
@michasaaucer:您应该自己将IsEnabled
属性添加到视图模型类中,然后将其绑定到视图的IsEnabled
属性。任务完成后,不要将其设置为true。谢谢!我在我的按钮中添加了Binding=ButtonEnableState
,我在VM
类中创建了属性,它可以工作!请编辑您的答案,以便将来帮助他人:)我有一个小问题,我使用get,set
创建了类似您的属性(IsEnabled
),我在AcceptButton
上将其设置为false,但在启动窗口时,它被设置为false
(在我单击按钮之前)。你能告诉我,如何仅在我单击按钮时触发false
,而不是在之前吗?@michasaaucer:将属性默认设置为true
:bool isEnabled{get;Set;}=true代码>