在Entity Framework加载数据时显示忙碌指示器 [英] Displaying a busy indicator when Entity Framework is loading data

查看:48
本文介绍了在Entity Framework加载数据时显示忙碌指示器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去,通过使用BusyIndi​​cator作为我的根元素,并将IsBusy属性绑定到RIA Services生成的域上下文的IsLoading属性,我已经很容易使用Silverlight做到这一点:

I've already done it quite easily in the past with Silverlight, by declaring a BusyIndicator as my root element, and binding the IsBusy property to the IsLoading property of the domain context generated by RIA Services:

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

由于实体框架生成的ObjectContext上似乎没有 IsLoading 属性,因此如何在WPF中绑定IsBusy属性?

Since there seems to be no IsLoading property on the ObjectContext generated by Entity Framework, how can I bind the IsBusy property in WPF?

谢谢

推荐答案

我想出了什么:

WPF扩展工具包中的忙碌指示器:

Busy Indicator from the WPF Extended Toolkit:

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

在基类视图模型中,添加了以下方法:

In my base class view model, I've added the following method:

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

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

当我想从服务器加载集合时,可以从派生的视图模型中调用:

When I want to load a collection from the server, I can call from a derived view model:

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

There's also a more robust & complete solution on CodeProject: http://www.codeproject.com/KB/WPF/ThreadingComponent.aspx?msg=3319891

这篇关于在Entity Framework加载数据时显示忙碌指示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆