开发者

Silverlight databinding doesn't work

开发者 https://www.devze.com 2023-04-08 16:23 出处:网络
Below you can see a part of my class definitions: public class Package { public int PackageId { get; set; }

Below you can see a part of my class definitions:

public class Package {
  public int PackageId { get; set; }
  public string Name { get; set; }
}

public class Member {
  public int MemberId { get; set; }
  public strin开发者_开发技巧g DisplayName { get; set; }
}

public class MemberPackage {
  public int PackageId { get; set; }
  public int MemberId { get; set; }
  public DateTime DateSold { get; set; }

  public Member Member { get; set; }
  public Package Package { get; set; }
}

These are EF 4 model classes. I pull MemberPackage objects from WCF RIA services and bind them to a DataGrid on the UI. To show the package names I use a binding syntax shown below:

<sdk:DataGridTextColumn Header="Package Name" Binding="{Binding Path=Package.Name}" />
<sdk:DataGridTextColumn Header="Date Sold" Binding="{Binding DateSold}" />

Nothing comes up under the Package Name column but I can see the Date Sold values. What's going on here, doesn't it supposed to work this way?

Thanks in advance.


The problem could be that when you get the MemberPackages in the service/factory, make sure you have the .Include("Package") as below:

return this.ObjectContext.MemberPackages
                .Include("Package");

This should bring back the Package details as part of the MemberPackage and then your binding to Package.Name should work.


It is something to do with the data context of the view - are you sure Package is a property on your view model (data context) and do the models implement INotifyPropertyChanged?


Simply remove the Path= and have this:

<sdk:DataGridTextColumn Header="Package Name" Binding="{Binding Package.Name}" />

You don't need to specify the path.

If that doesn't work then you should need to make sure that the Package member of MemberPackage has the [Include] attribute in the server side definition. This will ensure that the whole hierarchy is serialised to the client. I didn't suggest this at first as I assume that your code was edited.

0

精彩评论

暂无评论...
验证码 换一张
取 消