我的视图模型是:
public class SampleViewModel : ViewModelBase
{
private bool isBusy;
public bool IsBusy
{
get { return isBusy; }
set { isBusy = value;
RaisePropertyChanged("IsBusy"); }
private string prop1;
public string Prop1
{
get { return prop1; }
set { prop1 = value;
RaisePropertyChanged("Prop1"); }
}
private string prop2;
public string Prop2
{
get { return prop2; }
set { prop2 = value;
RaisePropertyChanged("Prop2"); }
}
private string prop3;
public string Prop3
{
get { return prop3; }
set { prop3 = value;
RaisePropertyChanged("Prop3"); }
}
public SampleViewModel()
{
new Task(() => LoadProp1Async()).Start();
new Task(() => LoadProp2Async()).Start();
new Task(() => LoadProp3Async()).Start();
}
private void LoadProp1Async()
{
Thread.Sleep(5000);
Prop1 = "a";
}
private void LoadProp2Async()
{
Thread.Sleep(15000);
Prop2 = "b";
}
private void LoadProp3Async()
{
Thread.Sleep(10000);
Prop3 = "c";
}
}
看法:
<toolkit:BusyIndicator BusyText="Loading..." IsBusy="{Binding IsBusy}" />
我想在 viewmodel 属性 IsBusy == true 时显示 throbber。当三个任务中的任何一个正在运行时,此属性为真。
我怎样才能做到这一点?我个人有一个解决方案(使用调解器),但我不喜欢它。