Adding dynamic controls to Silverlight application after WCF Service Asynchronous Callback
Posted
by
Birk
on Stack Overflow
See other posts from Stack Overflow
or by Birk
Published on 2011-01-12T03:50:20Z
Indexed on
2011/01/12
3:53 UTC
Read the original article
Hit count: 302
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
© Stack Overflow or respective owner