首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何访问DataGrid.RowDetailsTemplate中的控件?

如何访问DataGrid.RowDetailsTemplate中的控件?
EN

Stack Overflow用户
提问于 2013-07-13 16:46:35
回答 2查看 2.2K关注 0票数 2

以下是我的XAML:

代码语言:javascript
复制
<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控件。提前谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-07-13 17:35:44

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

代码语言:javascript
复制
private void outerGrid_LoadingRowDetails(object sender, DataGridRowDetailsEventArgs e)
{
    DataGrid innerGrid = e.DetailsElement as DataGrid;
    if (innerGrid != null)
    {

    }
}
票数 1
EN

Stack Overflow用户

发布于 2013-11-26 02:20:46

感谢kmatyaszek的正确答案。之前,我尝试使用RowDetailsTemplate.LoadContent(),它不会更新UI,但可以获取对象。

下面是我更新的示例代码:

代码语言:javascript
复制
    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...";
                        }
                    }
                }
            }
        }
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17628522

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档