Can someone tell me what I am doing wrong.....I am able to use the following syntax to bind the results of a Linq query(Jobs - IEnumerable<XElement> property on my view model) to a standard ListBox: How do I make this happen with XamDataGrid? I've posted my failed attempt at the bottom. Thanks!
<ListBox ItemsSource="{Binding Jobs}" Height="150">
<ListBox.ItemTemplate>
<DataTemplate DataType="{}Job">
<StackPanel Orientation="Horizontal">
<TextBlock Width="100" Text="{Binding Path=Element[JOB_ID].Value}" />
<TextBlock Width="100" Text="{Binding Path=Element[TYPE_DESCR].Value}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
--------------------
<igDP:XamDataGrid IsUndoEnabled="True" Theme="Office2k7Blue" DataSource="{Binding Jobs}" IsEnabled="True">
<igDP:XamDataGrid.FieldLayoutSettings>
<igDP:FieldLayoutSettings
HeaderPrefixAreaDisplayMode="FieldChooserButton"
AutoGenerateFields="False"
AllowClipboardOperations="All"
CopyFieldLabelsToClipboard="True" />
</igDP:XamDataGrid.FieldLayoutSettings>
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout>
<igDP:FieldLayout.Fields>
<igDP:Field DataType="{x:Type xlinq:XElement}" Name="Element[JOB_ID].Value" Label="Job Id"/>
<igDP:Field DataType="{x:Type xlinq:XElement}" Name="Element[TYPE_DESCR].Value" Label="Job Type"/>
<igDP:UnboundField Name="ActionItem" Label="Action Item"/>
<igDP:UnboundField Name="Overdue" Label="Overdue"/>
<igDP:UnboundField Name="Upcoming" Label="Upcoming"/>
</igDP:FieldLayout.Fields>
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>
Thanks again Andrew! That was it. I hope this helps the other LINQ users...
It would get called for every item in the root collection and every item within the expandable field cell values - i.e. if an item actually has items for a given expandable field. I think your issue is that you were using Element[Submittal] but you want all the Submittal instances so it would be Elements[Submittal]. I've taken your xml and added to it to demonstrate the other possibility (i.e. if Job contained a single element that then contained the elements that should be considered as children). I then created a sample that demonstrates how to set up both ways - the situation you had with the direct elements and the child element which contains the elements that would be the child record items. Hopefully this will help other people looking to set this up.
Almost....the Job showed a "+" but then disappeared when I clicked to open it. I checked the AssigningFieldLayoutToItem event and it is only getting fired once where it correctly assigns the Job field layout. Should it be called again to assign the submittal layout for that collection? I included the xml. Would a work-around be just to take the linq query results and convert it to standard xml and bind via xmldataprovider? I am using 9.2 with the latest service pack. Thanks for the help!
<Job> <JOB_ID>1000</JOB_ID> <Submittal> <ENTITY_DESCR URL="test">Wood Doors-Bldg C</ENTITY_DESCR> <EARLY_LATE_AMT>-712</EARLY_LATE_AMT> <ENTITY_ID>R</ENTITY_ID> <D_ACTION_DUE_DATE>2008-03-14</D_ACTION_DUE_DATE> <ASSIGNED_TO>Timothy Johnson</ASSIGNED_TO> <COMM_REF_ACTION_DESCR>Addl Info Required</COMM_REF_ACTION_DESCR> </Submittal> <Submittal> <ENTITY_DESCR URL="test">Toilet Accessories</ENTITY_DESCR> <EARLY_LATE_AMT>-712</EARLY_LATE_AMT> <ENTITY_ID>10800-1.0</ENTITY_ID> <D_ACTION_DUE_DATE>2008-03-14</D_ACTION_DUE_DATE> <ASSIGNED_TO>Timothy Johnson</ASSIGNED_TO> <COMM_REF_ACTION_DESCR>Addl Info Required</COMM_REF_ACTION_DESCR> </Submittal> <Submittal> <ENTITY_DESCR URL="test">Hardware - Bldg D</ENTITY_DESCR> <EARLY_LATE_AMT>-712</EARLY_LATE_AMT> <ENTITY_ID>08700-1.0</ENTITY_ID> <D_ACTION_DUE_DATE>2008-03-14</D_ACTION_DUE_DATE> <ASSIGNED_TO>Timothy Johnson</ASSIGNED_TO> <COMM_REF_ACTION_DESCR>Addl Info Required</COMM_REF_ACTION_DESCR> </Submittal>
</Job>
Its hard to say for sure without knowing the xml structure but since you are not setting the DataType of the unbound field it is left at object. Try setting the DataType to something like DataType="{x:Type sys:ICollection}" where sys is xmlns:sys="clr-namespace:System.Collections;assembly=mscorlib".
Note you are going to have to tell the DataPresenter what field layout is used with each record since in all cases the object type is the same - xelement. In 9.1 and earlier the only way to do that is to handle the AssigningFieldLayoutToItem event. LIkely to do this you would look at the e.Item in that event and based upon the Name of the element choose which FieldLayout so you'll want to set a Key on the FieldLayouts so you can index into the collection. In 9.2 and later, you can set the ParentFieldLayoutKey and ParentFieldName. e.g.
I now have the need for this to support hierarchical data......ie. a parent->child. Can I do this using unbound fields? The following field layouts produced 1 row with a submittal field that contains my submittal xml.
<igDP:UnboundField BindingPath="Element[JOB_ID].Value" Label="Job Id"/>
<igDP:UnboundField BindingPath="Element[Submittal]" Label="Submittal"/>
<igDP:UnboundField BindingPath="Element[Description].Value" Label="Description"/>
<igDP:UnboundField BindingPath="Element[EarlyLateAmt].Value" Label="EarlyLateAmt"/>