2010-11-19 50 views
3

过去我已经很容易地使用Silverlight完成它,通过将BusyIndi​​cator声明为我的根元素,并将IsBusy属性绑定到生成的域上下文的IsLoading属性通过RIA服务:当实体框架加载数据时显示繁忙的指示器

<toolkit:BusyIndicator IsBusy="{Binding Context.IsLoading}" > 

由于似乎没有IsLoading财产由实体框架生成的ObjectContext的,我怎么可以绑定在WPF中IsBusy财产?

谢谢

回答

0

我想出什么样的主意:

从WPF工具包扩展指标忙:

<extoolkit:BusyIndicator IsBusy="{Binding IsBusy}" BusyContent="Loading data..." > 

在我的基类视图模型,我已经添加了以下方法:

protected void ExecuteBackgroundProcess(Action action) 
    { 
     IsBusy = true; 

     Task task = Task.Factory.StartNew(() => action()).ContinueWith((s) => this.IsBusy = false); 
    } 

当我想从服务器加载集合时,我可以从得到的视图模型:

this.ExecuteBackgroundProcess(() => 
{ 
    var collection = _securityRepo.TakeOfType<Security>(10).ToObservableCollection(); 

    DispatcherHelper.CheckBeginInvokeOnUI(() => 
    { 
     Securities = collection; 
     RaisePropertyChanged("Securities"); 
    });      
}); 

还有CodeProject上更强大的&完整的解决方案: http://www.codeproject.com/KB/WPF/ThreadingComponent.aspx?msg=3319891