2016-08-26 106 views
0

我嘗試更新UI時遇到問題。我需要的是,在顯示BusyIndicator之後,需要更改消息,並且在完成5秒後,顯示另一條消息兩秒鐘,然後隱藏BusyIndicator。謝謝!WPF Toolkit BusyIndi​​cator

XAML

<xctk:BusyIndicator IsBusy="{Binding IsBusy}" DisplayAfter="0"> 
    <xctk:BusyIndicator.BusyContentTemplate> 
     <DataTemplate> 
      <StackPanel> 
       <mahApps:ProgressRing IsActive="{Binding IsBusy}"/> 
       <Label Content="{Binding ShowMessage}"/> 
      </StackPanel> 
     </DataTemplate> 
    </xctk:BusyIndicator.BusyContentTemplate> 

    ... 

</xctk:BusyIndicator> 

XAML視圖模型

public string ShowMessage 
{ 
    get { return _showMessage; } 
    set 
    { 
     _showMessage = value; 
     RaisePropertyChanged("ShowMessage"); 
    } 
} 

private void Save() 
{ 
    ShowMessage = "Wait please..."; 

    Task.Factory.StartNew(() => 
    { 
     IsBusy = true; // Show busyindicator and ProgressRing 

     Thread.Sleep(5000); // 5 seconds to see the animation (Here is a SQL insert) 

     /// Hide ProgressRing only 

     ShowMessage = "Save complete."; 

     Thread.Sleep(2000); // 2 seconds to see "ShowMessage" 

    }).ContinueWith(x => 
    { 
     IsBusy = false; // hide busyindicator and ProgressRing 

     ... 

    }, TaskScheduler.FromCurrentSynchronizationContext()); 
} 

enter image description here

回答

0

有點晚了,但是,ShowMessage = 「保存完整。」沒有在UI線程上運行。爲使RaisePropertyChanged能夠正常工作,您需要插入另一個Continuation和Task來使用FromCurrentSynchronizationContext執行ShowMessage。

相關問題