I have simple dashboard that I created in asp.net that I am trying to convert to Silverlight. The problem I am facing is the WCF services run asynchronously and some controls depend on others.
Ideally I want to:
- Load the data in the page. 4 WCF Services
- Set the Datacontext of user controls
- Load user controls dependent form data
- Set the default control data
- Run report in user control based on default values
1&2) I have about 4 objects that are loading asynchronous in the page which each control needs. When those are loaded, I set the DataContext on each of the objects. I am not crazy about my solution. What I did was set a bool for each object loaded in the completed event and when they are all loaded then set the DataContext. The object I pass has properties for all 4 objects
3) I am thinking of having a public method (LoadFormData) on each user control class which I can execute from the Page when I am setting the datacontext 5) Do the same in 1 & 2, where I have a bool for each piece of data loaded in the user control, when they are all loaded I can run the report.Basically, I wanted to know a better/more elegant way of doing this.
Page
|__ User Control 1 |__ U开发者_Go百科ser Control 2 |__ User Control 3 |__ User Control 4 |__ User Control 5I've just found this blog post about getting two Silverlight controls to communicate. The example looks long winded, but it's basically using JavaScript to do the communication.
In Control A you call a piece of JavaScript (from his example):
HtmlPage.Window.Invoke("changeColor", clicky.Name);
Then in the JavaScript on the page you call a method in Control B:
function changeColor(color) {
slObject = document.getElementById("ControlB");
slObject.Content.Page.ChangeBackgroundColor(color);
}
This is a trivial example, but in your case you'd need to make the JavaScript call in Control A when it's ready. This can then make calls into your other controls which will allow them to do their stuff.
精彩评论