Reputation: 515
I have a silverlight application that uses WCF, and I would like to make a WCF call to load some data before the usercontrol is loaded so that I could use the data with an autocompletebox. Any suggestions as to how to accomplish this?
Upvotes: 1
Views: 863
Reputation: 8232
All WCF service calls in Silverlight are asynchronous. I've learned to use Lambdas and a very useful class called Action (which is a wrapper for an event and a delegate). Using the application startup as RobSiklos suggested would work great for getting it before showing the control. This shows the code that could also work inside of the userControl loaded event, incorporating a loading overlay (you could use a border with centered text that goes over the whole app or a Silverlight toolkit control). This approach will give more immediate feedback to the user, especially if your data service call will take a longer time.
public MyUserControl : UserControl
{
public MyUserControl()
{
this.Loaded += new RoutedEventHandler(View_Loaded);
}
void View_Loaded(object sender, RoutedEventArgs e)
{
// start showing loading overlay
MyService service = new Service(...);
service.GetDataCompleted += (o, args) =>
{
var data = args.Results;
// hide loading overlay
}
}
}
Upvotes: 0
Reputation: 1621
Not sure if your user interface will be suitable to use a loading indicator or a progress bar. If you can use loading indicator, then it might be a good option to display the busy / loading indicator while the async call is in progress. That would disable the user from clicking on the dropdown or any other control while the data is being retrieved from the WCF service.
Upvotes: 1
Reputation: 8849
You can do the async call in the Application_Startup()
method of your App.xaml.cs
file, and set RootVisual
in your async callback instead of in Application_Startup()
.
Upvotes: 0