我在实现显示忙碌指示器的控件时遇到了一些问题,情况如下:我有一个带有忙碌指示器和 TextBlock 的简单 View ,它绑定(bind)到 ViewModel(如下所示)。
public class ViewModel
{
private bool _isbusy;
public bool IsBusy
{
get { return _isbusy; }
set
{
_isbusy=value;
OnPropertyChanged("IsBusy");
}
}
private string _text;
public string Text
{
get { return _text; }
set
{
_text = value;
OnPropertyChanged("Text");
}
}
public void CallMe()
{
IsBusy = true;
Text = Static.PerformCalculation();
IsBusy = false;
}
}
到目前为止一切都很简单,不是吗?问题是当我有像 CallMe() 这样的方法时。我必须在计算完成时显示和隐藏忙碌指示器,我认为原因是计算和 IsBusy 属性通知是在同一个线程上完成的,所以我想出了这样的事情:
public void CallMe()
{
IsBusy = true;
Static.PerformCalculationAsync(CalculationCallback);
}
private void CalculationCallback(string result)
{
Text = result;
IsBusy = false;
}
现在发生了一些不同的事情,Busy Indicator 加载正常,但是当计算时间太短时,BusyIndicator 不会显示,并且在调用 CallMe() 方法和文本出现在屏幕上之间有一个小的延迟。 这是我的问题,我希望在隐藏 BusyIndicator 之前计算 Text 属性(并显示在屏幕上)。
有没有人知道这样做的好方法,或者有什么建议我可以遵循?
最佳答案
busyindicator
控件需要
DisplayAfter="0"
关于silverlight - 如何在计算过程中显示 Silverlight Toolkit Busy Indicator?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6722034/