[英]WPF Toolkit BusyIndicator
我在尝试更新UI时遇到问题。 我需要的是在显示BusyIndicator
,需要更改消息,并且在5秒钟完成后,显示另一条消息2秒钟,然后隐藏BusyIndicator
。 谢谢!
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());
}
有点晚了,但是ShowMessage =“保存完成。”; 不在UI线程上运行。 为了使RaisePropertyChanged正常工作,因此您需要插入另一个Continuation and Task以使用FromCurrentSynchronizationContext执行ShowMessage。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.