以下是我的XAML:
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<DataGrid Name="innerGrid" IsReadOnly="True" AutoGenerateColumns="False" Margin="10,10,5,5" Width="400" HorizontalAlignment="Left">
<DataGrid.Columns>
<DataGridTextColumn Header="Ref" Binding="{Binding Id}"/>
<DataGridTextColumn Header="Investor" Binding="{Binding FundProvider.FullName}"/>
<DataGridTextColumn Header="Amount" Binding="{Binding InvestmentAmount}"/>
</DataGrid.Columns>
</DataGrid>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
我的问题是如何从代码中访问innerGrid
DataGrid
控件。在此先感谢。
答案 0 :(得分:1)
您可以访问DataGrid
事件(msdn)中的内部LoadingRowDetails
。
private void outerGrid_LoadingRowDetails(object sender, DataGridRowDetailsEventArgs e)
{
DataGrid innerGrid = e.DetailsElement as DataGrid;
if (innerGrid != null)
{
}
}
答案 1 :(得分:0)
感谢kmatyaszek的正确答案。 以前我在尝试使用RowDetailsTemplate.LoadContent(),虽然能够获取对象但是没有更新UI。
这是我更新的示例代码:
void gridEmployee_LoadingRowDetails(object sender, DataGridRowDetailsEventArgs e)
{
Border border = e.DetailsElement as Border;
if (border != null)
{
foreach (var grid in border.GetVisualChildren())
{
Grid grid_ = grid as Grid;
if (grid_ != null)
{
foreach (var textBlock in grid_.GetVisualChildren())
{
TextBlock textBlock_ = textBlock as TextBlock;
if (textBlock_ != null && textBlock_.Text == "City : ")
{
textBlock_.Text = "My assigned text...";
}
}
}
}
}
}