Search code examples
silverlightlinqwcf-ria-services

Databinding with comboxBox in silverlight


I am trying to use a dataContext to populate a comboxbox but always got nothing:

EntityQuery<Tests> testQ = myDomainContext.GetTestQuery().Where(t => t == 5);
LoadOperation<Tests> loadOp = myDomainContext.Load(testQ)
comboxBoxTest.ItemSource = loadOp.Entities.Select(t => t.Name).Distinct().ToList();

Can someone tell me what is wrong here?


Solution

  • You probably don't load the entities. Try

    EntityQuery<Tests> testQ = myDomainContext.GetTestQuery().Where(t => t == 5);
    LoadOperation<Tests> loadOp = myDomainContext.Load(testQ);
    loadOp.Completed += (o, e) =>
        {
            comboxBoxTest.ItemSource = loadOp.Entities.Select(t => t.Name).Distinct().ToList();
        };
    

    Or

    myDomainContext.Load(testQ, new Action<LoadOperation<Tests>>(result =>
        {
            comboxBoxTest.ItemSource = result.Entities.Select(t => t.Name).Distinct().ToList();
        }), null);