如何在DataGrid RowDetailsTemplate中获取Control

时间:2011-04-19 10:23:15

标签: wpf wpf-controls wpfdatagrid

我有这个Xaml代码,我想获取DataGrid“dgRemplacement”,我尝试使用Name,但它也不适用于Uid。

<DataGrid.RowDetailsTemplate>
         <DataTemplate>
            <Grid Background="#FF4088C0" Name="DetailGrid">
             <TabControl>                           
                 <TabItem Header="Detaille">                                
                 </TabItem>
                        <TabItem Header="Intervention">                                
                        </TabItem>
                        <TabItem Header="Detaille Intervention">                                
                 </TabItem>
                        <TabItem Header="Remplacement">
                            <Grid Background="#FFE5E5E5">
                                <DataGrid Name="dgRemplacement" x:Uid="DataGrid1">
                                    <DataGrid.Columns>
                                        <DataGridTextColumn Header="Article(Serie)" Binding="{Binding Designation}"/>
                                        <DataGridTextColumn Header="Qte" Binding="{Binding Qte}"/>
                                    </DataGrid.Columns>                                        
                                </DataGrid>
                            </Grid>
                        </TabItem>                          
            </TabControl>
            </Grid>
            </DataTemplate>
        </DataGrid.RowDetailsTemplate>
private void dgBILigne_RowDetailsVisibilityChanged(object sender, DataGridRowDetailsEventArgs e)
{
        TabControl tc = (e.DetailsElement as Grid).Children[0] as TabControl;
        TabItem ti = tc.Items[3] as TabItem;
}

我成功获得了TabItem

1 个答案:

答案 0 :(得分:0)

尝试类似:

var dataGrid = (e.DetailsElement as FrameworkElement).FindName("dgRemplacement") as DataGrid;

FindName Reference