0

how to access the control inside the Popup. popup is accessable but why i cant access datagrid inside the popup.how can we access all child control inside a DataTemplate

 <DataGrid  ItemsSource="{Binding}" AutoGenerateColumns="False" Height="193" CanUserAddRows="False" 
 HorizontalAlignment="Left" Margin="48,12,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="560"
              CellEditEnding="dataGrid1_CellEditEnding" >
        <!--Resources Start-->
        <DataGrid.Resources>
            <Style TargetType="{x:Type DataGridCell}">
                <EventSetter Event="GotFocus" Handler="DataGridCell_GotFocus" />
            </Style>
        </DataGrid.Resources>
        <!--Resources End-->
        <DataGrid.Columns>
            <!--Ledger Head Start-->
            <DataGridTemplateColumn Header="Ledger Head" Width="200" >

                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding LedgerHead}"/>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
                <DataGridTemplateColumn.CellEditingTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <TextBox Text="{Binding LedgerHead}" Loaded="TextBox_Loaded"  KeyUp="TextBox_KeyUp" />
                            <Popup x:Name="popup1"  AllowsTransparency="True"  PopupAnimation="Slide" Width="500" Height="800"  PlacementTarget="{Binding ElementName=textPopUp}" >
                                <Grid>
                                    <DataGrid x:Name="datagrid2"></DataGrid>
                                </Grid>
                            </Popup>
                        </StackPanel>

                    </DataTemplate>
                </DataGridTemplateColumn.CellEditingTemplate>
            </DataGridTemplateColumn>
  • The problem is not the grid but the datatemplate. Why you must do that? – Gianluca Conte Sep 14 '18 at 10:23
  • You should get popup1.Child and use VisualTreeHelper to findChild. you can get my code from https://github.com/Ilya-Grigoryan/SynchDataGridScroll.git and see the VisualTreeHelperEx.cs, with this extension you can find any child that you want to. – Ilya Grigoryan Sep 14 '18 at 10:55
  • Check this https://stackoverflow.com/questions/52312441/i-cannot-get-the-selection-box-in-my-xbox-uwp-app-popup/52316289#52316289 – Mac Sep 14 '18 at 12:05
  • auto complete a combobox or textbox in datagrid cell . – Aaron stephen A S K Sep 14 '18 at 12:15
  • what i am trying to do is show in the above code.But i can not access datagrid2 in the pop up.We can access popup1 but we are not able to access datagrid2 because that child control not accessable inside popup 1. – Aaron stephen A S K Sep 14 '18 at 12:17

1 Answers1

0

No, We can not access controls inside a data template using its names. but,

  1. to assign data source to the grid view, you can do it in the loaded event of grid by type casting sender to gridview.
  2. to get the selected data of grid, you can use the selectionchanged event of grid by type casting sender to gridviewitem.