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.6k views Asked by vkg At
3
There are 3 answers
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
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.
Here is the simpler solution that worked for me.
In the XAML:
However, note that the property name is "GroupByRecords", so maybe it doesn't work if your records are not grouped.