0

Let me preface this by saying, I'm not sure if this is even possible. I've got two similar collections of complex objects that I'm using as source data for two different Items controls. Well, let's call the first collection the old data, and let's call the second collection the new data.

Like I said above, I've got two items controls - one binding to old, and the other binding to new. Well, in the item template of the new items control, I want to be able to bind to the old data, however I need to be able to use an index because the property is List of items. Maybe code snippets will help explain what I'm after:

<ItemsControl.ItemTemplate>
     <DataTemplate>
          <Textblock Text="{Binding Path=OldSourceData.MyList[0]}"/>
     </DataTemplate>
</ItemsControl.ItemTemplate>

However, I need to replace 0 with the alternation index of the current item. I'm using this to get the correct index {Binding Path=(ItemsControl.AlternationIndex), RelativeSource={RelativeSource TemplatedParent}}

How do I replace 0 with the alternation index?

EDIT I'm trying to figure out how to do something like this: <Textblock Text="{Binding Path=OldSourceData.MyList[{Binding Path=(ItemsControl.AlternationIndex), RelativeSource={RelativeSource TemplatedParent}}]}"/> Obviously, this syntax doesn't work, however is it possible to accomplish this somehow?

Brandon
  • 3,074
  • 3
  • 27
  • 44
  • duplicate https://stackoverflow.com/questions/22378456/how-to-get-the-index-of-the-current-itemscontrol-item – Evgeny Gorbovoy Apr 19 '18 at 20:08
  • @EugeneGorbovoy It's not a duplicate. I can grab the alternation index using the above code, however is it possible to put that code inside of the square brackets ```[0]``` when accessing an item from ```OldSourceData```? – Brandon Apr 19 '18 at 20:10
  • 1
    Not possible to put inside, but you can use converter to do that, like in link provided. Also if you want to put it inside you need to create your own MarkupExtension – Evgeny Gorbovoy Apr 20 '18 at 08:24

0 Answers0