如何保持 SfDataGrid 的 DetailsView 展开?

How to keep the DetailsView of a SfDataGrid expanded?

我有一个 SfDataGrid,我为此制作了一个 DetailsViewDefinition。我还从代码中制作 ExpandAllDetailsView 以展开所有细节,我想保持这些打开,但在第一次重新排序或第一次重新组合之后,这些将崩溃。

我尝试了重新打开每个事件(有意义的),但只有 MouseUp 最接近目标,但这有点糟糕,因为它不适用于 header 和将在每次 mouseups 时重新打开,所以这是一个非常糟糕的 hack。

我想知道一种有效的方法 即使在 reorder/group.

等事件发生后也能保持 rowdetail 打开

您可以使用SfDataGrid.ExpandAllDetailsView方法实现您的要求。对于分组,可以通过SfDataGrid.GroupColumnDescriptions.CollectionChanged事件,

来实现
this.dataGrid.GroupColumnDescriptions.CollectionChanged += GroupColumnDescriptions_CollectionChanged;
private void GroupColumnDescriptions_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
 {
dataGrid.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.ApplicationIdle,
          new Action(() =>
          {
              this.dataGrid.ExpandAllDetailsView();
          }));
 }

对于排序,您可以通过 SfDataGrid.SortColumnsChanged 事件实现,

this.dataGrid.SortColumnsChanged += DataGrid_SortColumnsChanged;

private void DataGrid_SortColumnsChanged(object sender, GridSortColumnsChangedEventArgs e)
{
    dataGrid.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.ApplicationIdle,
         new Action(() =>
         {
             this.dataGrid.ExpandAllDetailsView();

         }));
}

Sample

此致,

Susmitha S