I have a Xamdatagrid having hierarchical data.I want to display all such records expended automatically.So that user doesn't have to click on + icon for each record.
Auto expand hierarchical data rows in Xamdatarrid
1.7k Views Asked by vkg At
3
There are 3 best solutions below
0
On
The above answer is good but for those who prefer to see this as a defined behavior, here's another take at it:
public class AutoExpandXamDataGridRecordBehavior : Behavior<XamDataGrid>
{
protected override void OnAttached()
{
if (AssociatedObject is XamDataGrid grid)
{
grid.InitializeRecord += OnInitializeRecord;
}
}
protected override void OnDetaching()
{
if (AssociatedObject is XamDataGrid grid)
{
grid.InitializeRecord -= OnInitializeRecord;
}
}
private void OnInitializeRecord(object sender, InitializeRecordEventArgs e)
{
((XamDataGrid)sender).ExecuteCommand(DataPresenterCommands.ToggleRecordIsExpanded, e.Record);
}
}
0
On
Here is the simpler solution that worked for me.
In the XAML:
<!-- namespace -->
xmlns:ig="http://schemas.infragistics.com/xaml/wpf"
<ig:XamDataGrid>
<ig:XamDataGrid.FieldSettings>
<ig:FieldSettings ExpandGroupByRecordsByDefault="True" />
</ig:XamDataGrid.FieldSettings>
</ig:XamDataGrid>
However, note that the property name is "GroupByRecords", so maybe it doesn't work if your records are not grouped.
You can handle the XamDataGrid's InitializeRecord event (or override OnInitializeRecord) like so:
There's also DataPresenterCommands.ExpandRecord, which expands the grid's ActiveRecord.