Adding dynamic controls to Silverlight application after WCF Service Asynchronous Callback
- by Birk
I'm trying to add some dynamic controls to my Silverlight page after a WCF call. When I try to add a control to I get an error: Object reference not set to an instance of an object.
Here is a simplified version of my code:
using edm = SilverlightBusinessApplication.ServiceRefrence;
public partial class ListWCF : Page
{
edm.ServiceClient EdmClient = new ServiceClient();
public ListWCF()
{
EdmClient.GetTestCompleted += EdmGetTestCompleted;
EdmClient.GetTestAsync();
}
private void EdmGetTestCompleted(object sender, edm.GetTestCompletedEventArgs e)
{
//This is where I want to add my controls
Button b = new Button();
LayoutRoot.Children.Add(b); //Error: Object reference not set to an instance of an object
}
}
Is it not possible to modify the page after it has been loaded? What am I missing?
Thanks