Displaying a busy indicator when Entity Framework is loading data

后端 未结 1 769
天命终不由人
天命终不由人 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:

    <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");
        });                       
    });
    

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

    0 讨论(0)
提交回复
热议问题