I have a SL application that reads some data from the database, which I do through a WCF Service. I was having some delay problems due to this access, so I solved it by loading all the data into a dictionary in my app. Now I want to make sure the application will only be displayed after I loaded all this information, how can I do that? I thought that just puting my InitializeComponents after the data load would be enough, but it is not. Here is some piece of my code:
public Brasil()
{
//InitializeComponent();
webService = new DataRetrieverReference.DataRetrieverClient();
webService.GetCounterCompleted += new EventHandler<WebPortos.DataRetrieverReference.GetCounterCompletedEventArgs>(webService_GetCounterCompleted);
webService.GetCounterAsync();
webService.GetDataCompleted += new EventHandler<DataRetrieverReference.GetDataCompletedEventArgs>(webService_GetDataCompleted);
}
void webService_GetCounterCompleted(object sender, WebPortos.DataRetrieverReference.GetCounterCompletedEventArgs e)
{
int counter = e.Result;
this.dictionary = new Dictionary<int, WebPortos.DataRetrieverReference.vwPortos_SEP>();
for (int i = 0; i < counter; i++)
{
webService.GetDataAsync(i);
}
InitializeComponent();
}
As you can see, I put it inside my data loading method, but it didn’t work. Any tips?
It is bad practice to delay the creation of views in any way. Leave InitializeComponent in the constructor! 🙂
What you want to do is simply hide your display until the data is ready. Easiest way (to keep this example simple) is start with Visibility set to collapsed on some parent element on the page, then set that to Visible again after the data is loaded.
Real world solutions involve using busy indicators to stop interaction with specific areas/controls while the data loads.