I need the Expand / Collapse for RowDetailsTemplate

前端 未结 5 970
北荒
北荒 2020-12-09 09:56

I have a DataGrid. It has DataGrid.RowDetailsTemplate. When a button is clicked it should Expand / Collapse; how would I do that?

&         


        
5条回答
  •  遥遥无期
    2020-12-09 10:45

    Instead of walking the tree to find the datagrid row from the expander, use the static method GetRowContainingElement which is found on DataGridRow. Such as:

    private void Expander_Process(object sender, RoutedEventArgs e)
    {
        if (sender is Expander expander)
        {
            var row = DataGridRow.GetRowContainingElement(expander);
    
            row.DetailsVisibility = expander.IsExpanded ? Visibility.Visible 
                                                        : Visibility.Collapsed;
        }
    }
    

    Then the expander has only one method call for each of the events:

     
    

提交回复
热议问题