2016-08-26 5 views
0

UIの更新中に問題が発生しました。私が必要とするのは、BusyIndicatorを表示した後、メッセージの変更が必要であり、5秒後に2秒間別のメッセージを表示してから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のViewModel

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が動作するためには、FromCurrentSynchronizationContextを使用してShowMessageを実行するために別のContinuationとTaskを挿入する必要があります。

関連する問題