Binding Listview item's subitem to another data

I have a Listview in my app that has a ItemTemplate that has three TextBlocks. the Listview's ItemsSource property is set to a List named "units" in my class named "ConversionEngine"...

so my problem is: I want to Bind the second and third TextBlocks in the ItemTemplate to another List in the same "ConversionEngine" class. but I can't, bucause the Listview's ItemsSource property is set to "units" List of string and all the subitems of ItemTemplate inherit the "units" list. how can I Bind the sub items to another list, in the same class of ConversionEngine, or another classes that I define? Thanks... here are my codes:

The Listview:

<ListView x:Name="allunits" **ItemsSource="{Binding units}**" SelectionMode="Single" IsItemClickEnabled="True" ItemClick="allunit_itemclick" SelectedIndex="-1" ItemTemplate="{StaticResource Standard500x130ItemTemplate}"/>

The ItemTemplate Code:

<DataTemplate x:Key="Standard500x130ItemTemplate">

        <Grid Height="110" Width="480" Margin="10" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Border Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}" Width="110" Height="110">
                <Image Source="{Binding Image}" Stretch="UniformToFill"/>
            </Border>
            <StackPanel Grid.Column="1" VerticalAlignment="Top" Margin="10,0,0,0">
              **<TextBlock Text="{Binding}" Style="{StaticResource TitleTextStyle}"/>**
              **<TextBlock  Text="{Binding ??}" Style="{StaticResource TitleTextStyle}/>**
              **<TextBlock  Text="{Binding ??}" Style="{StaticResource TitleTextStyle}"/>**
            </StackPanel>
        </Grid>
    </DataTemplate>

Answers


Itemscontrol items can only bind to UI elements, things which can be accessed using relative source and parts of the datacontext which they are given. My suggestion would be to either consolidate your different lists into one list, or at the very least, return grouped items from your bound property. So either:

public class CompositeItem
{
  Item item;               //item from your first list
  Item2 item2;             //item from your second list
  . . .
}

//main class
List<CompositeItem> items;  //list of combined items

or:

public Tuple<Item, Item2 . . . > items //bind your items control to this
{
    List<Tuple<Item, Item2 . . >> newListOfItems = new Tuple<Item, Item2 . . >(); 
    for(int i = 0; i < items.count; i++)
    {
        newListOfItems.add(new Tuple<Item, Item2 . . >(list1[i], list2[i] . . .));
    }
    return newListOfItems;
}

Need Your Help

how to know indexpath of UITableView.visibleCells?

ios objective-c uitableview

NSArray * arrayOfVisibleTVC=[BNUtilitiesQuick ListController].tableViewA.visibleCells;