none
How Can I get a Control inside DataGrid RowDetailTemplate RRS feed

  • Question

  • I have this Xaml Code and I want to get the DataGrid "dgRemplacement", I try using Name but it doesn't work also with 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;
    }

    I have succeeded to get the TabItem
    lundi 18 avril 2011 08:40

Réponses

  • Bonjour ,

     

    Essayer le code suivant pour retrouver votre DataGrid :

     

    public static DependencyObject ResearchType(DependencyObject element, Type researchType)
        {
          if (element == null) return null;
          if (element.GetType() == researchType) return element;
          DependencyObject parent = VisualTreeHelper.GetParent(element);
          return ResearchType(parent, researchType);
        }
    
        private void dgBILigne_RowDetailsVisibilityChanged(object sender, DataGridRowDetailsEventArgs e)
        {
          ResearchType(e.DetailsElement as Grid, typeof(DataGrid));
        }
    


    Cordialement, Pascal.

    Développeur Wpf/SilverLight/WinPhone7

    mardi 26 avril 2011 19:23
    Modérateur