我有一个窗口中包含的列表(见下文)。窗口的DataContext
有两个属性,Items
和AllowItemCommand
。WPF数据绑定:如何访问“父”数据上下文?
如何获取Hyperlink
的Command
属性需要根据窗口的DataContext
来解析的绑定?
<ListView ItemsSource="{Binding Items}">
<ListView.View>
<GridView>
<GridViewColumn Header="Action">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<TextBlock>
<!-- this binding is not working -->
<Hyperlink Command="{Binding AllowItemCommand}"
CommandParameter="{Binding .}">
<TextBlock Text="Allow" />
</Hyperlink>
</TextBlock>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
你可以进入调试器并逐步完成UI的构建点吗?如果是的话,你可以进入变量,并尝试钻取 – 2009-07-14 20:49:52
简单的解决方案(这也适用于Windows 8商店/ Metro应用程序)在这里:[http://stackoverflow.com/questions/15366609/how-to-access-父母-的datacontext-在窗口-8-商店的应用程式/ 15419382#15419382](http://stackoverflow.com/questions/15366609/how-to-access-parents-datacontext-in-window-8-store-apps/15419382#15419382) – LMK 2013-06-13 03:18:55