我有一个Xamdatagrid有分层数据。我想显示所有这些自动消耗的记录。所以用户不必点击每个记录的+图标。
答案 0 :(得分:2)
您可以像这样处理XamDataGrid的InitializeRecord事件(或覆盖OnInitializeRecord):
void grid_InitializeRecord(object sender, Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs e)
{
grid.ExecuteCommand(DataPresenterCommands.ToggleRecordIsExpanded, e.Record);
}
还有DataPresenterCommands.ExpandRecord,它扩展了网格的ActiveRecord。
答案 1 :(得分:0)
上述答案很好,但对于那些喜欢将其视为明确行为的人来说,还有另一种观点:
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);
}
}