在行详细子网格

时间:2017-10-11 09:44:43

标签: c# wpf datagrid

我有一个主WPF数据网格,其中包含两个网格上带有selectionchanged三角形的详细“子”数据网格

<DataGrid x:Name="RepertoiresDataGrid"
            SelectionChanged="RepertoiresDataGrid_SelectionChanged">
..
..
  <DataGrid.RowDetailsTemplate>
    <DataTemplate>
      <DataGrid x:Name="CommentsDataGrid"  
                  CanUserAddRows="True"
                  CanUserDeleteRows="True"
                  CanUserSortColumns="True"
                  ItemsSource="{Binding Path=Comments}"
                  SelectionUnit="FullRow"
                  SelectionChanged="CommentsDataGrid_SelectionChanged">
      .. 
      ..

支持代码

    private void CommentsDataGrid_SelectionChanged(object sender, 
                                        SelectionChangedEventArgs e)
    {

    }

    private void RepertoiresDataGrid_SelectionChanged(object sender, 
                                         SelectionChangedEventArgs e)
    {
        CommentsAsync(sender);
    }

RepertoiresDataGrid_SelectionChanged按预期工作,因为它在RepertoiresDataGrid中更改选择时触发

CommentsDataGrid_SelectionChanged几乎按预期工作,因为它会在CommentsDataGrid中更改选择时触发,但在触发此选项后,也会触发RepertoiresDataGrid_SelectionChanged。

在处理CommentsDataGrid_SelectionChanged调用后是否可以停止事件链?

1 个答案:

答案 0 :(得分:0)

添加e.Handled = true;到了

private void CommentsDataGrid_SelectionChanged(object sender, 
                                    SelectionChangedEventArgs e)
{
    e.Handled = true;
}

这将停止事件链。