2010-11-19 63 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