Good Afternoon!
I have a xamDataGrid that looks similar to below. As the user selects Detail Types on the page, I programmatically add an unbound field for each Detail Type to the data grid. In the example below, the user has two detail types selected (ABC and DEF).
Detail Type: ABC DetailType: DEF
Interval Ending Value Value Hidden Column
5/1/2013 01:00:00 5 4 DetailTypes (0=ABC, 1=DEF)
5/1/2013 02:00:00 4 4 DetailTypes (0=ABC, 1=DEF)
5/1/2013 03:00:00 5 3 DetailTypes (0=ABC, 1=DEF)
Field.Tag = 0 Field.Tag = 1
When adding the unbound fields, I am binding directly to the property in my entity that is displayed.
.BindingPath = New PropertyPath("DetailTypes[" & loop & "].Value")
I am also setting the unbound field's tag property to its index in the collection.
.Tag = loop
When formatting the Value cells, I need to access quite a few other properties that exist in the original entity, besides Value. So I created a hidden field that is bound to my DetailTypes collection referenced above. It exists in Record.Cells[2].
<Style x:Key="BaseValueFieldStyle" TargetType="{x:Type igDP:CellValuePresenter}" BasedOn="{StaticResource {x:Type igDP:CellValuePresenter}}" >
<Setter Property="Background" Value="{Binding Record.Cells[2].Value[0].Difference, RelativeSource={RelativeSource Self}, Converter={StaticResource Test}}" />
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<igWindows:CardPanel>
<TextBlock HorizontalAlignment="Right">
<TextBlock.Text>
<Binding Path="Record.Cells[2].Value[0].Value" RelativeSource="{RelativeSource AncestorType={x:Type igDP:CellValuePresenter}}" />
</TextBlock.Text>
</TextBlock>
</igWindows:CardPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
Currently I have 0 hard-coded in my binding path on my styles. The code works, and it binds to the Value and Difference properties on the first entity in my collection (Detail Type: ABC). Is there any way to replace the 0 in my binding dynamically with the index that exists in Field.Tag? I have tried quite a few things with no luck.
Thanks in advance!
Hello Alicia,
Thank you for your post. I have been looking into it and have created a small sample application to test the functionality. In order to achieve the desired functionality I have a button, which adds the columns with the data from the DetailTypes collection. Removing the Value at the end of the binding for the property path would bind the UnboundField directly to the DetailTypes collection. Then you can use only the Value.Difference and Value[0].Value for the two bindings.
Please find the attached sample application and feel free to let me know if you have any further questions on this matter.
Thank you for your assistance!