2

以下是我的 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从代码中访问控制。提前致谢。

4

2 回答 2

1

DataGrid您可以在LoadingRowDetails事件 ( msdn )中访问内部。

private void outerGrid_LoadingRowDetails(object sender, DataGridRowDetailsEventArgs e)
{
    DataGrid innerGrid = e.DetailsElement as DataGrid;
    if (innerGrid != null)
    {

    }
}
于 2013-07-13T09:35:43.960 回答
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...";
                        }
                    }
                }
            }
        }
    }
于 2013-11-25T18:20:46.150 回答