如何在C#背后的代码中访问datatemplate内部的网格控件名称

时间:2018-09-14 09:54:53

标签: c# wpf

如何访问弹出窗口中的控件。弹出窗口是可访问的,但是为什么我不能访问popup内部的datagrid。我们如何访问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>

0 个答案:

没有答案