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.
Asked
Active
Viewed 1,543 times
3 Answers
2
You can handle the XamDataGrid's InitializeRecord event (or override OnInitializeRecord) like so:
void grid_InitializeRecord(object sender, Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs e)
{
grid.ExecuteCommand(DataPresenterCommands.ToggleRecordIsExpanded, e.Record);
}
There's also DataPresenterCommands.ExpandRecord, which expands the grid's ActiveRecord.

user1676558
- 403
- 1
- 6
- 18
0
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);
}
}

Glaucus
- 848
- 8
- 14
0
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.

Arkane
- 352
- 4
- 10