在 Silverlight 中,子控件视图模型如何访问父数据上下文?
背景:
我有类似于以下伪代码的 xaml
...
<DataContext><vm:parentVM/></DataContext>
<Grid x:Name="LayoutRoot">
...
<local:myControl Grid.Column="0" Grid.Row="1" DataContext="{Binding vmChild}" />
问题:
当我在视图模型 vmChild 的上下文中处理一些代码时,如何访问视图模型 vmParent 中的属性和方法
BACKGROUND:
I have xaml similar to the following pseudo code
...
<DataContext><vm:parentVM/></DataContext>
<Grid x:Name="LayoutRoot">
...
<local:myControl Grid.Column="0" Grid.Row="1" DataContext="{Binding vmChild}" />
QUESTION:
When I am processing some code in the context of the view model vmChild, how do I access properties and methods in the view model vmParent
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:假设列表框的数据上下文位于您的子虚拟机中,而父虚拟机是一个网格,其数据上下文是从父虚拟机设置的。一些施展诡计可以让你获得货物。
Try this: Assuming the Listbox's data context is in your childVM and the parent is a Grid which has its data context set from the ParentVM. Some casting trickery can allow you to access the goods.