I have a DataGrid. It has DataGrid.RowDetailsTemplate. When a button is clicked it should Expand / Collapse; how would I do that?
&
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: