Silverlight 3 RIA controls and how they load

If you have started playing with the RIA controls for Silverlight, one thing that you will need to understand is that when you get a DomainContext and call one of the load commands, that it does this async.

So if you do something like:

 var context = new TestDomainContext();
context.LoadProducts();
foreach (Product p in context.Products)
{
    myComboBox.Items.Add(p.ProductName);
}

You will get nothing put into your ComboBox.  You need to hook up to the Loaded event and when that fires, then you can load up your ComboBox:

 var context = new TestDomainContext();
context.LoadProducts();
context.Loaded += new EventHandler
            <System.Windows.Ria.Data.LoadedDataEventArgs>
            (context_Loaded);

void context_Loaded(object sender,
            System.Windows.Ria.Data.LoadedDataEventArgs e)
{
    var context = sender as TestDomainContext;

    foreach (Product p in context.Products)
    {
        myComboBox.Items.Add(p.ProductName);
    }
}

Just wanted to get that out there in case anyone else runs into that issue.