Well, I already know I can do it by defining two different field layouts and giving them names like so:
<igWPF:Field Name="MAKE" Label="Make" />
<igWPF:Field Name="MODEL" Label="Model" /> <igWPF:Field Name="FuelEconomy" Label="Mileage" /> </igWPF:FieldLayout>
<igWPF:FieldLayout x:Name="Trucks"> <igWPF:Field Name="BRAND" Label="Brand" /> <igWPF:Field Name="MODEL" Label="Model" />
<igWPF:Field Name="GroundClearance" Label="Ground Clearance" />
I was able to choose a field layout in code behind by handling the AssigningFieldLayoutToItem event. Basically I just look at the type of the bound Item and then apply the named filed layout with:
e.FieldLayout = Cars
e.FieldLayout = Trucks.
However, to fit an MVVM pattern a little better I think it would be much better to have a DataTemplateSelector kind of like ListBox has. So what would be nice is a declarative way to select a FieldLayout based on type. Is this possible?
Thank you for your post. I have been looking into your question and by default, a FieldLayout is assigned to a record, based on the match between the properties of the DataItem of the record and the Fields in the FieldLayout.Fields collection. This means, that when you have a record, that holds a Car object with Model and Make properties and you have two FieldLayouts in the XamDataGrid: one with Model and Make fields and one with Brand and Model and the Car class does not have a Brand property, the XamDataGrid will choose the first FieldLayout for this record, since the fields of the layout are matching to the properties of the item of the record. You can read more details on FieldLayouts here: http://help.infragistics.com/NetAdvantage/WPF/current/CLR4.0/?page=InfragisticsWPF4.DataPresenter.v13.1~Infragistics.Windows.DataPresenter.FieldLayout.html
If, in your scenario, the Truck and the Car classes both have Model, Brand and Make properties and you have two FieldLayouts: one with Model and Make fields and the other with Brand and Model field, the XamDataGrid will choose the first FieldLayout by its index in the FieldLayouts collection of the XamDataGrid, and will assign it to the Record, regardless of its item, since both FieldLayouts has matching field names with the properties of the item of the record. In this scenario, if you wish to be able to set the one FieldLayout to be used for Car and the other for Truck, I can suggest using the Key property of the FieldLayout. When setting the FieldLayout’s Key property to the type of the object, this FieldLayout will be used for the type that the Key is specifying. For example, if you have the following FieldLayouts:
<igWPF:Field Name="Make" />
<igWPF:Field Name="Model" />
<igWPF:Field Name="Brand" />
And you have Car and Truck classes with the same properties: Model, Make, Brand and you set the DataSource of the XamDataGrid to a collection of Trucks, the second FieldLayout will be used, since its key is “Truck”, as the name of the class used in the data source. If the FieldLayouts have not Key set, the first FieldLayout will be used for both Cars and Trucks. I have created a sample application that demonstrates this functionality.
Please let me know if you need any further assistance on the matter.
Developer Support Engineer
I am just checking if you require any further assistance on the matter.