Blog Archives
Global BusyIndicator for DomainDataContext
Posted by schuits
Problem:
With Asynchronous calls in Silverlight its important to let the user know something is happening when they request data. At first I put a BusyIndictor in the Navigation content, which was ugly because it left a large border showing around the BusyIndicator for those elements that are not part of the Navigation content.
Solution
What I was looking for was some way, on an application level, to show a BusyIndicator. I came across this post by Bryan Sampica which was very useful. http://weblogs.asp.net/bryansampica/archive/2010/07/09/global-busyindicator-for-domaincontext.aspx
This worked perfectly on a DomainContext level, BUT, I was using a bunch of DomainDataSources, which would always be busy for longer than the DomainContext itself. Which meant the BusyIndicator dissapeared before the actual data was available…what a pity.
So I kept the concept of using a BusyIndicator as the rootvisual, but ditched the domaincontext class extension. And then just manipulated the Global BusyIndicator depending on whether the DomainDataSource is loading or not.
Something like this.
domainDataSource1.Load();
BusyIndicator busy = (BusyIndicator)App.Current.RootVisual;
busy.IsBusy = true;
private void DomainDataSource1_LoadedData(object sender, LoadedDataEventArgs e)
{
…
BusyIndicator busy = (BusyIndicator)App.Current.RootVisual;
busy.IsBusy = false;
}
The DomainDataSource1’s LoadedData event is handled by DomainDataSource1_LoadedData