How do I bind a domain context to a data grid ? Ria Services + Silverlight

47 Views Asked by At

These past days I've tried to understand the concept of invoked methods and domain contexts, but some things are still not so clear to me.

In my StudentDomainService I have this method:

[Invoke]
    public IEnumerable<Student> GetStudents()
    {
        return _studentRepository.GetStudents();
    }

This returns a list of students that I want to bind to my datagrid using a viewmodel.

In my StudentViewModel I have:

private StudentDomainContext _studentDomainContext;
private InvokeOperation<IEnumerable<Student>> _students;
public StudentViewModel()
    {
        _studentDomainContext = new StudentDomainContext();
        _students = _studentDomainContext.GetStudents(OnInvokeCompleted, null);
    }

    public void OnInvokeCompleted(InvokeOperation<IEnumerable<Student>> studs)
    {
        if (studs.HasError)
        {
            studs.MarkErrorAsHandled();
        }
        else
        {
            var result = studs.Value;
        }
    }

    public InvokeOperation<IEnumerable<Student>> Students
    {
        get { return _students; }
        set
        {
            _students = value;
            RaisePropertyChanged("Students");
        }

    } 

And in StudentView I have a datagrid and I'm trying to bind to the Students property like this:

ItemsSource="{Binding Students}"

But when I start the application the data grid appears but it's not displaying anything. Can anyone please tell me what I'm doing wrong?

UPDATE I think the problem is that the OnInvokeCompleted() method is not executing on the UI, but I'm not really sure.

0

There are 0 best solutions below