Displaying a busy indicator when Entity Framework is loading data

后端 未结 1 759
天命终不由人
天命终不由人 2021-01-06 17:17

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 o

1条回答
  •  不知归路
    2021-01-06 17:40

    What I came up with:

    Busy Indicator from the WPF Extended Toolkit:

    
    

    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(10).ToObservableCollection();
    
        DispatcherHelper.CheckBeginInvokeOnUI(() =>
        {
            Securities = collection;
            RaisePropertyChanged("Securities");
        });                       
    });
    

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

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题