我的应用程序执行Web服务调用,当它发生时,IsExecuting状态设置为true,并且执行按钮被禁用。由于在此期间应用程序没有响应,因此我更改了进程,以便在单独的线程中执行。然而,我现在注意到的问题是,执行按钮仍然被禁用,只有当我点击界面按钮启用。我怎样才能解决这个问题?WPF CanExecute和线程池
编辑: 在代码隐藏:
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}"/>
我已经试过这一点,但它并没有帮助。 – Sys
@sys,试图调用UI线程这种方法(使用Dispatcher.Current.Invoke) –
我试过Application.Current.Dispatcher.Invoke(新的行动(代表{IsExecuting = TRUE;}));但再次不工作... – Sys