主/详细数据网格。如何访问Detail DataGrid来设置ItemsSource?
在典型的主/细节情况下......
我有一个数据网格。此 DataGrid 的 ItemsSource 在 WCF 调用的 Completed 事件中设置 - (grdMaster.ItemsSource = e.Result) - 其中网格的 x:Name 是 grdMaster。这都是100%的。
但是,当在主网格 DataTemplate 中添加详细数据网格并对其进行适当命名时......我的代码隐藏无法识别详细网格。简单地说,我无法像设置 grdMaster 那样设置 grdDetail 的 ItemsSource。
根据所选的主项目,我需要执行 WCF 调用来获取适当的详细信息。
In a typical Master/Detail situation...
I have a DataGrid. The ItemsSource of this DataGrid is set in the Completed event of a WCF call - (grdMaster.ItemsSource = e.Result) - where the x:Name of the grid is grdMaster. This is all 100%.
However, when adding a Detail Datagrid inside the master grids DataTemplate and naming it appropriately... my codebehind does not recognise the detail grid. So plainly put, I cannot set the ItemsSource of grdDetail like I do with grdMaster.
Depending on the Master item selected, I need to do a WCF call to get the appropriate Details.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据如何通知您正在选择要扩展的项目,您将需要找到用户所在的行:
并更新行详细信息可见性:
除了这些详细信息之外,您还需要为详细信息行创建一个样式 -它连接到一个您可以监听的事件:
它被设置为网格的 RowDetailsTemplate:
在 LoadingRow 事件中,您可以获得对所涉及的数据上下文的引用,并保存对子数据网格的引用,以便在 WCF 调用后您可以设置 ItemsSource:
希望有帮助,
Depending on how you are being notified that an item is being selected for expansion you will need to find the row the user is in:
and update the row details visibility:
Those details aside, you need to create a style for the details rows -- which is wired to an event you can listen to:
which is set as the RowDetailsTemplate for your grid:
Within the LoadingRow event you can obtain a reference to which data context is involved, and save a reference to the child data grid so that after a WCF call you can set the ItemsSource:
Hope that helps,