I put together a small test app to test databinding between XamDataGrid and my business objects (ObservableCollections based on Rocky Lhotka's CSLA framework). Some of the columns were to be hidden, some needed comboboxes, etc., so I added a FieldLayout and Fields to my XAML. And so that I could see the results, I added some XML sample data that I could bind to at design time.
Using the XML data, I was able to get all my comboboxes and formatting working. However, when I instead point to the ObjectDataProvider for my ObservableCollection, I get my data, but the FieldLayout is completely ignored, i.e. no fields are hidden, no comboboxes, no alternate headers supplied by labels, etc. All the columns are there, and header labels are generated from the field names, but no formatting.
I tried setting AutoGenerateFields to False, but in that case got nothing at all.
Here is the XAML:
<Page x:Class="TestPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:igDP="http://infragistics.com/DataPresenter" xmlns:igEditors="http://infragistics.com/Editors" xmlns:local="clr-namespace:Tracker" xmlns:data="clr-namespace:TrackerLibrary;assembly=TrackerLibrary" mc:Ignorable="d" d:DesignHeight="480" d:DesignWidth="640" Title="TestPage" > <Grid Name="LayoutGrid"> <Grid.Resources>
<XmlDataProvider x:Key="SampleProjects" Source="../DataSources/SampleProjects.xml" XPath="Projects/Project" IsAsynchronous="False" IsInitialLoadEnabled="True"/> <ObjectDataProvider x:Key="Projects" ObjectType="{x:Type data:TrackingCollection}" MethodName="GetTrackingCollection" IsAsynchronous="False" IsInitialLoadEnabled="True"/>
<igEditors:ComboBoxItemsProvider x:Key="AssigneeItemsProvider" /> <Style x:Key="AssigneeFieldStyle" TargetType="{x:Type igEditors:XamComboEditor}"> <Setter Property="ItemsProvider" Value="{DynamicResource AssigneeItemsProvider}" /> </Style> </Grid.Resources>
<!--<igDP:XamDataGrid Name="ProjectGrid" Theme="IGTheme" DataSource="{Binding Source={StaticResource SampleProjects}}" >--> <igDP:XamDataGrid Name="ProjectGrid" Theme="IGTheme" DataSource="{Binding Source={StaticResource Projects}}" >
<igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:Field Name="TrackingID" Label="TrackingID" Width="Auto" Visibility="Collapsed"/> <igDP:Field Name="ShortDescription" Label="Description" FixedLocation="FixedToNearEdge" Width="Auto"/> <igDP:Field Name="Priority" Label="Priority" Width="Auto"/> <igDP:Field Name="Status" Label="Status" Width="Auto"/> <igDP:Field Name="Category" Label="Category" Width="Auto"/> <igDP:Field Name="AssigneeID" Label="Assigned To" Width="Auto"> <igDP:Field.Settings> <igDP:FieldSettings EditorStyle="{StaticResource AssigneeFieldStyle}" /> </igDP:Field.Settings> </igDP:Field> <igDP:UnboundField Name="Entity" Label="System/Entity" Width="Auto" /> <igDP:Field Name="ComponentID" Label="Component" Width="Auto" /> <igDP:Field Name="OrgAffectedID" Label="Site Affected" Width="Auto"/> <igDP:Field Name="OrgReportingID" Label="Site Reporting" Width="Auto"/> <igDP:Field Name="ReportedBy" Label="Reported By" Width="Auto"/> <igDP:Field Name="OpenDate" Label="Open Date" Width="Auto" /> <igDP:Field Name="OpenedBy" Label="Opened By" Width="Auto"/> <igDP:Field Name="LastUpdateDate" Label="Last Update Date" Width="Auto"/> <igDP:Field Name="LastUpdatedBy" Label="Last Updated By" Width="Auto"/> <igDP:Field Name="CloseDate" Label="Close Date" Width="Auto"/> <igDP:Field Name="FullDescription" Label="FullDescription" Width="Auto" Visibility="Collapsed"/> <igDP:Field Name="Resolution" Label="Resolution" Width="Auto" Visibility="Collapsed"/> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid> </Grid></Page>
I didn't include code-behind because the only thing in it is a short routine to load the combobox, which is working, at least in the XMLprovider version.
Any idea why this is happening? The only thing I change is which XamDataGrid line is commented out. It seems to me that if the FieldLayouts work with one datasource collection they ought to work with another.
The only other unusual thing is that at designtime I have a squiggly line under my ObjectDataProvider and a message, "Exception has been thrown by the target of an invocation.", but I assume that's because it's unable to actually execute the method until runtime.
Hello,
Thank you for your post
I have been looking into your code I am not able to see anything wrong with the declaration of the FieldLayout. I copied your code locally and it was working fine, so the only possible reason I can see for such behavior is inconsistency with the names provided in the Field’s declaration and the actual names of the properties in the TrackingCollection object. This was the only way I manage to prevent the layout from your example, from being applied – by putting one or more wrong Field names.
Since the layout has been applied within the xaml but its not working with the collection I assume that you have different names set, because it seems that the layout was functioning fine before you provide the new data source. If only one Field’s Name does not match its corresponding property name from the data source object, your fields will be automatically generated and your customization will not be applied and this is one very likely reason why do you get this behavior.
Can you please verify that every field and its corresponding property names and in case the issue still stands, send me some working isolated sample in order for me to investigate deeper.
I will be looking forward to hearing from you.
Sincerely,
Ekaterina
Developer Support Engineer
Infragistics, Inc.
www.infragistics.com/support
Actually, it turned out to be a missing field rather than a misspelled one, but you put me on the right track.