我的应用程序执行 web 服务调用,当它发生时,IsExecuting 状态设置为 true 并且执行按钮被禁用。因为在此期间应用程序没有响应,所以我更改了进程,因此执行发生在单独的线程中。但是我现在注意到的问题是,执行按钮仍然被禁用,只有当我点击界面时,按钮才会启用。我怎样才能解决这个问题?
编辑:在代码隐藏中:
private void Execute()
{
ThreadPool.QueueUserWorkItem(new WaitCallback(ExecuteThread));
}
private bool CanExecute
{
get { return !IsExecuting; }
}
private void ExecuteThread(Object o)
{
IsExecuting = true;
// Process execution here ...
IsExecuting = false;
}
In Xaml:
<Button Content="Execute" Command="{Binding Path=ExecCommand}"/>