Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
285
WPF Binding with Indexed Property
posted

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!