Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF:无法访问内部数据网格_C#_Wpf_Xaml - Fatal编程技术网

C# WPF:无法访问内部数据网格

C# WPF:无法访问内部数据网格,c#,wpf,xaml,C#,Wpf,Xaml,我对WPF中的一个内部元素有问题。它是innerGrid数据网格。 我无法在代码中访问它,只能访问普通的Datagrid。我忘了在xaml代码中添加一些东西了吗 <DataGrid x:Name="dataGrid" ItemsSource="{Binding Path = data, IsAsync=True}" HorizontalAlignment="Left" Height="198" Margin="35,38,0,0" VerticalAlignment="Top" Wid

我对WPF中的一个内部元素有问题。它是innerGrid数据网格。 我无法在代码中访问它,只能访问普通的Datagrid。我忘了在xaml代码中添加一些东西了吗

  <DataGrid x:Name="dataGrid" ItemsSource="{Binding Path = data, IsAsync=True}" HorizontalAlignment="Left" Height="198" Margin="35,38,0,0" VerticalAlignment="Top" Width="474" AutoGenerateColumns="False" IsReadOnly="True">
        <DataGrid.RowHeaderTemplate>
            <DataTemplate>
                <Expander Expanded="Expander_Expanded" Collapsed="Expander_Collapsed">
                </Expander>
            </DataTemplate>
        </DataGrid.RowHeaderTemplate>
        <DataGrid.RowDetailsTemplate>
            <DataTemplate>
           <DataGrid x:Name="innerGrid" Height="200">
                    <DataGrid.Columns>
                        <DataGridTextColumn  Header="Patientennummer" />
                    </DataGrid.Columns>
                </DataGrid>
               </DataTemplate>
             </DataGrid.RowDetailsTemplate>
             </DataGrid>

您可以在主“dataGrid”的LoadingRowDetails事件中访问内部网格

或者,您可以为“内部网格”添加“已加载”事件,在该事件处理程序中,您可以使用内部网格执行任何操作


希望这有帮助。

您可以在主“dataGrid”的LoadingRowDetails事件中访问内部网格

或者,您可以为“内部网格”添加“已加载”事件,在该事件处理程序中,您可以使用内部网格执行任何操作


希望这能有所帮助。

如果您尝试以“innerGrid”的形式访问它,会发生什么情况?他将无法从代码隐藏中访问它作为其当前的内部数据模板。当我尝试访问它时,会出现以下错误:“innerGrid”的名称在当前上下文中不存在。您认为为什么需要访问它?在Xaml中,无论您正在做什么,几乎肯定都可以做得更好如果您尝试以“innerGrid”的形式访问它会发生什么?他将无法从代码隐藏中访问它作为其当前的内部数据模板。当我尝试访问它时,会出现以下错误:“innerGrid”的名称在当前上下文中不存在。您认为为什么需要访问它?无论您在做什么,几乎可以肯定在XAML中都可以做得更好
private void dataGrid_LoadingRowDetails(object sender, DataGridRowDetailsEventArgs e)
    {
        DataGrid innerGrid = e.DetailsElement as DataGrid;

        if (innerGrid != null)
        {
        }
    }