我的應用程序執行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