Wpf 2表格上的数据网格

Wpf 2表格上的数据网格,wpf,xaml,datagrid,grid,Wpf,Xaml,Datagrid,Grid,我在一个表单上发布了两个DataGrid,但在第二个表单中DataGrid绑定不起作用。 属性项使用它们显示相同的值。如果第二次更改中有一次自动更改。 如何使其正常工作 <DataGrid Margin="8,72.04,8,-34" Name="AskDataGrid" ItemsSource="{Binding Path=Вопросы}" SelectedCellsChanged="AskDataGrid_Selected

我在一个表单上发布了两个DataGrid,但在第二个表单中DataGrid绑定不起作用。 属性项使用它们显示相同的值。如果第二次更改中有一次自动更改。 如何使其正常工作

<DataGrid Margin="8,72.04,8,-34" 
          Name="AskDataGrid"
          ItemsSource="{Binding Path=Вопросы}"
          SelectedCellsChanged="AskDataGrid_SelectedCellsChanged">

</DataGrid>

<DataGrid Margin="8,62,8,48.96"  
          Grid.Row="1" 
          Name="AnswersDataGrid" 
          AutoGenerateColumns="True" 
          ItemsSource="{Binding Path=Ответы}"
          SelectionChanged="AnswersDataGrid_SelectionChanged">
</DataGrid>

您可以尝试以下方法:

<DataGrid Margin="8,62,8,48.96"  
      Grid.Row="1" 
      Name="AnswersDataGrid" 
      AutoGenerateColumns="True" 
      ItemsSource="{Binding Path=Ответы}"
      SelectedIndex="{Binding ElementName=AskDataGrid, Path=SelectedIndex}"
      SelectionChanged="AnswersDataGrid_SelectionChanged">
</DataGrid>


顺便说一下。。。在代码中使用俄语不是一个好主意。。。我试过了,但什么也没发生。但是我写的是AnswersDataGrid.ItemsSource=myDataSet.Tables[“Answers”].DefaultView;在C#代码中,这是有效的。。。很奇怪。。。我创建了两个数据网格,并为它们提供了相同的ItemSources——第二个数据网格的SelectedIndex与第一个数据网格中的SelectedIndex发生了变化……您需要显示您的数据上下文,即包含绑定到的字段的类。