如何将列表框绑定到位于我的 ViewModel 中的复杂类型中的集合?
我的视图模型当前包含一个“SelectedClient”属性,它引用数据网格中选定的“Client”对象。该选定的客户端属性包含一个名为“OfficeLocations”的属性,该属性本质上只是“OfficeLocation”对象的列表。
我试图将列表框绑定到 SelectedClients.OfficeLocations 属性,如下所示:
<ListBox ItemsSource="{Binding SelectedClient.OfficeLocations}" />
但由于某种原因,列表框始终显示为空白。再次,在调试模式下,当我查看 SelectedClient.OfficeLocations 属性时,它实际上包含数据。
我也尝试过类似的方法:
<ListBox ItemsSource="{Binding SelectedClient, Path=OfficeLocations}" />
无济于事。
任何想法将不胜感激..谢谢!
My view model currently contains a "SelectedClient" property which refers to the selected "Client" object in a datagrid. This selected client property contains a property titled "OfficeLocations" which is essentially just a list of "OfficeLocation" objects.
I am trying to bind a listbox to the SelectedClients.OfficeLocations property like so:
<ListBox ItemsSource="{Binding SelectedClient.OfficeLocations}" />
But for some reason the ListBox always shows up blank. Once again, in debug mode when I view the SelectedClient.OfficeLocations property, it does in fact contain data.
I've also tried something like:
<ListBox ItemsSource="{Binding SelectedClient, Path=OfficeLocations}" />
To no avail.
Any ideas would be greatly appreciated..Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
啊,原来我正在尝试使用 DataGrid.RowDetailsTemplate 进行此绑定,该绑定已经将我的 DataContext 覆盖为 SelectedItem...这意味着将我的绑定更改为如下所示:
修复了问题!
Ahh, so it turns out that I was trying to do this binding with a DataGrid.RowDetailsTemplate which overrides my DataContext to SelectedItem already...meaning changing my binding to look like:
Fixed the issue!