Silverlight 这个 Binding 语句有什么问题?
我有一个Employees 集合,每个项目都有它自己的ProjectResource 项目集合。 我正在尝试对列进行数据绑定,但 ProjectResource 不会绑定。
<data:DataGrid x:Name="TestGrid">
<data:DataGrid.Columns>
<data:DataGridTextColumn Header="First Name"
Binding="{Binding Person.FirstName}" />
<data:DataGridTextColumn Header="Last Name"
Binding="{Binding Person.LastName}" />
<data:DataGridTextColumn Header="Week 1"
Binding="{Binding ProjectResource[0].PercentRequired}" />
</data:DataGrid.Columns>
<data:DataGridTextColumn Header="Week 2"
Binding="{Binding ProjectResource[1].PercentRequired}" />
</data:DataGrid.Columns>
</data:DataGrid>
从上面您可以看到我们从 Employee.Person 获取了 Name 详细信息,并且我们有 Employee.ProjectResource 子集合。 这就是我所拥有的。从逻辑上讲,它应该有效(无论如何对我来说),但事实并非如此。它显示名字和姓氏,但不显示项目资源数据。 也许这只是一个语法错误或一些简单的事情(我希望),但任何帮助将不胜感激。
感谢您的阅读
I have a collection of Employees, each item has it's own collection of ProjectResource items.
I'm trying to databind the columns but the ProjectResource won't bind.
<data:DataGrid x:Name="TestGrid">
<data:DataGrid.Columns>
<data:DataGridTextColumn Header="First Name"
Binding="{Binding Person.FirstName}" />
<data:DataGridTextColumn Header="Last Name"
Binding="{Binding Person.LastName}" />
<data:DataGridTextColumn Header="Week 1"
Binding="{Binding ProjectResource[0].PercentRequired}" />
</data:DataGrid.Columns>
<data:DataGridTextColumn Header="Week 2"
Binding="{Binding ProjectResource[1].PercentRequired}" />
</data:DataGrid.Columns>
</data:DataGrid>
From the above you can see we get the Name details from Employee.Person and we have the subcollection as Employee.ProjectResource.
This is what I have. It makes sense(to me anyway) logically it should work but it doesn't. It displays the first and last name but no projectresource data.
Perhaps it's just a syntax error or something simple(I hope) but any help would be appreciated.
Thanks for reading
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对此有一个解决方案,尽管它有点像黑客。
我在 silverlight 应用程序中创建了一个新的 Employee 和 Resource 类。我创建了一个集合,并将 Employee 实体项添加到新集合中,并将此新集合指定为网格的项源。对 xaml 进行一些轻微的语法修改后,它现在功能齐全,并且可以双向数据绑定到新集合。
我只需在启动 commitchanges 方法之前将所有更改导出回实体集合。
I have a fix for this though it's somewhat of a hack.
I created a newEmployee and Resource class within the silverlight app. I created a Collection and added the Employee entity items to the new collection and specified this new collection as the items source for the grid. After a few slight syntax mods to the xaml it is now fully functional and 2-way databound to the new collection.
I just have to export any changes back to the entity collection before initiating the submitchanges method.