Yes.
I set all my providers typically to IntiatlLoadEnabledd = false and use a
helper class to control the load. I also cover up the screen with
semi-transaparent grid to keep the user from clicking anywhere. Once load
is completed, you can hide the curtain.
Something
like this:
using System;
using
System.Collections.Generic;
using
Csla.Silverlight;
public class DataProviderLoadController
{
private Dictionary<CslaDataProvider, bool> _providers;
private EventHandler
_completedHandlers;
public event EventHandler
LoadAllCompleted
{
add
{
_completedHandlers = (EventHandler)System.Delegate.Combine(_completedHandlers,
value);
CheckAll();
}
remove
{
_completedHandlers = (EventHandler)System.Delegate.Remove(_completedHandlers,
value);
}
}
private
DataProviderLoadController() { }
public DataProviderLoadController(params object[] providers)
{
_providers = new Dictionary<CslaDataProvider, bool>();
foreach (CslaDataProvider item in providers)
{
_providers.Add(item, item.Data != null);
item.DataChanged += new EventHandler(item_DataChanged);
}
CheckAll();
foreach (CslaDataProvider item in providers)
{
if (item.IsInitialLoadEnabled == false)
{
item.Refresh();
}
}
}
private void
item_DataChanged(object sender, EventArgs e)
{
CslaDataProvider provider = sender as CslaDataProvider;
if (provider.Error != null)
_providers[provider] = true;
if (provider.Data != null)
_providers[provider] = true;
CheckAll();
}
private void CheckAll()
{
bool alldone = true;
foreach (var item in _providers.Values)
{
if (!item)
alldone = false;
}
if (alldone)
{
if (_completedHandlers != null)
{
_completedHandlers.Invoke(this, EventArgs.Empty);
foreach (var item in
_providers.Keys)
{
item.DataChanged -= new EventHandler(item_DataChanged);
}
_providers.Clear();
}
}
}
}
Sergey Barskiy
Principal Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: SouthSpawn
[mailto:cslanet@lhotka.net]
Sent: Friday, July 24, 2009 1:45 AM
To: Sergey Barskiy
Subject: [CSLA .NET] SilverLight Loading Objects
As we all know, that SL is Async.
Is it possible to have the loading screen delay until all
Async calls are done loading the page?
If so, can someone please point me to a code example.
Thanks
Copyright (c) Marimer LLC