I came across yet another Infragistics XamDataGrid bug the other day. I sent it to Infragistcs support, which is normally very good, but the guy working on this is having trouble understanding why this is a problem.
The bug concerns a parent layout that has two child layouts. It displays expanders and labels when it should not. Here's a sample XAML and code.
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp9"
xmlns:igDP="http://infragistics.com/DataPresenter"
mc:Ignorable="d"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
Title="MainWindow" Height="450" Width="800">
<Grid>
<igDP:XamDataGrid DataSource="{Binding Parents}">
<igDP:XamDataGrid.FieldSettings>
<igDP:FieldSettings AllowEdit="False"/>
</igDP:XamDataGrid.FieldSettings>
<igDP:XamDataGrid.FieldLayoutSettings>
<igDP:FieldLayoutSettings AutoGenerateFields="False" ExpansionIndicatorDisplayMode="CheckOnDisplay"/>
</igDP:XamDataGrid.FieldLayoutSettings>
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout Key="Parents">
<igDP:FieldLayout.Fields>
<igDP:TextField Label="Parent Name" Name="ParentName"/>
<igDP:Field Name="Children1"/>
<igDP:Field Name="Children2"/>
</igDP:FieldLayout.Fields>
</igDP:FieldLayout>
<igDP:FieldLayout ParentFieldLayoutKey="Parents" ParentFieldName="Children1" Key="Children1">
<igDP:FieldLayout.Settings>
<igDP:FieldLayoutSettings LabelLocation="Hidden"/>
</igDP:FieldLayout.Settings>
<igDP:FieldLayout.Fields>
<igDP:TextField Label="Name" Name="ChildName"/>
</igDP:FieldLayout.Fields>
</igDP:FieldLayout>
<igDP:FieldLayout ParentFieldLayoutKey="Parents" ParentFieldName="Children2" Key="Children2">
<igDP:FieldLayout.Settings>
<igDP:FieldLayoutSettings LabelLocation="Hidden"/>
</igDP:FieldLayout.Settings>
<igDP:FieldLayout.Fields>
<igDP:TextField Label="Name" Name="ChildName"/>
</igDP:FieldLayout.Fields>
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>
</Window>
Public Property ParentName As String
Public Property Children1 As List(Of cChild)
Public Property ChildName As String
End Class
{
New cParent() With {.ParentName = "Parent1",
End Class
The result looks like this.
I am not expecting Parent2 to have an expander button and I am not expecting the "Children1" and "Childrent2" labels because their location is set to hidden. I'm expecting it to look a bit like this when parent1 is expanded.
If I remove either of the child bands the grid behaves the way I expect.
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp9"
xmlns:igDP="http://infragistics.com/DataPresenter"
mc:Ignorable="d"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
Title="MainWindow" Height="450" Width="800">
<Grid>
<igDP:XamDataGrid DataSource="{Binding Parents}">
<igDP:XamDataGrid.FieldSettings>
<igDP:FieldSettings AllowEdit="False"/>
</igDP:XamDataGrid.FieldSettings>
<igDP:XamDataGrid.FieldLayoutSettings>
<igDP:FieldLayoutSettings AutoGenerateFields="False" ExpansionIndicatorDisplayMode="CheckOnDisplay"/>
</igDP:XamDataGrid.FieldLayoutSettings>
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout Key="Parents">
<igDP:FieldLayout.Fields>
<igDP:TextField Label="Parent Name" Name="ParentName"/>
<igDP:Field Name="Children1"/>
<!--<igDP:Field Name="Children2"/>-->
</igDP:FieldLayout.Fields>
</igDP:FieldLayout>
<igDP:FieldLayout ParentFieldLayoutKey="Parents" ParentFieldName="Children1" Key="Children1">
<igDP:FieldLayout.Settings>
<igDP:FieldLayoutSettings LabelLocation="Hidden"/>
</igDP:FieldLayout.Settings>
<igDP:FieldLayout.Fields>
<igDP:TextField Label="Name" Name="ChildName"/>
</igDP:FieldLayout.Fields>
</igDP:FieldLayout>
<!--<igDP:FieldLayout ParentFieldLayoutKey="Parents" ParentFieldName="Children2" Key="Children2">
<igDP:FieldLayout.Settings>
<igDP:FieldLayoutSettings LabelLocation="Hidden"/>
</igDP:FieldLayout.Settings>
<igDP:FieldLayout.Fields>
<igDP:TextField Label="Name" Name="ChildName"/>
</igDP:FieldLayout.Fields>
</igDP:FieldLayout>-->
</igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>
</Window>
InitializeRecord="XamDataGrid_InitializeRecord"
RecordExpanded="XamDataGrid_RecordExpanded"
RecordCollapsed="XamDataGrid_RecordCollapsed">
Dim dataItem As cParent
Dim diType As Type
Dim PI As PropertyInfo
Dim collection As IList
er.ExpansionIndicatorVisibility = Visibility.Collapsed
PI = diType.GetProperty(er.Field.Name)
collection = TryCast(PI.GetValue(dataItem), IList)
er.Visibility = Visibility.Collapsed
End If
End Sub
The XamDataGrid_InitializeRecord event handler collapses the expansion indicator for all Expandable records. If the IList it is expanding is empty the entire expandable record is collapsed. Note cParent could be replaced with Object to be more generic.
When we collapse the expander record, it will no longer be able to expand/collapse its children so we have to take responsibility for that ourselves when the parent record is expanded or collapsed.
I have not tested this with more complex hierarchies or when binding to datasets. But clearly, it can be done.
Ta Da! |
No comments:
Post a Comment