Silverlight -Pass Data from a parent to the child controls
I have a silverlight page which has about 5 user controls. Most of the controls are get开发者_如何学编程ting the same data from the database which I wanted to save some round trips to DB. I wanted to get the data in the main page and then pass it to the child controls. I tried creating a public property in the controls and setting them from the main page.
What is the best way of doing this?
Thanks.
From your description, it sounds like data binding would be your best approach (MSDN documentation). If you set the main control's DataContext to the object you retrieved from the database, all of the controls in that page will have access to the DataContext as well. This would also allow you to leverage data binding expressions to populate the properties of the UserControls' children.
精彩评论