2016-08-26 66 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。

相关问题