如果我想使用 XAML 绑定到父数据上下文数据,我可以编写以下内容:
<UserControl>
<RadGridView x:Name="Parentgrid">
<RadGridView.RowDetailsTemplate>
<DataTemplate>
<RadGridView x:Name="childGrid" ItemsSource="{Binding DataContext.Result, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
/>
</RadGridView.RowDetailsTemplate>
</RadGridView>
</UserControl>
但是考虑到代码在不同的类中,我如何使用代码来做到这一点,比如说附加属性。所以我可以访问发送者和参数,如下所示:
parentGrid.LoadingRowDetails += (sender, args) =>
{
RadGridView gridView = args.DetailsElement.FindName("childGrid") as RadGridView;
if (gridView != default(RadGridView))
{
gridView = //Should be able to access DataContext.Result
}
};