【发布时间】:2013-04-08 20:39:57
【问题描述】:
如何在 windows phone 8 中访问父元素的数据上下文? AncestorType 在 WP8 中不可用。
<ItemsControl x:Name="Elements" ItemsSource="{Binding MyList}" Grid.Row="2" Grid.Column="3">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="e" Width="100" Height="100" Command="{Binding MyCommand" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
“MyCommand”在“MyList”之外定义。那么如何从我的按钮访问根数据上下文(DataContext = MyClass)。 MyCommand 在 MyClass 类中定义。
提前致谢。
【问题讨论】:
标签: xaml binding windows-phone-8 commandbinding