在listitem中的windows phone 7 observablecollection

时间:2012-10-26 12:04:53

标签: windows-phone-7

我有一个ObservableCollection<testItem>,每个testItem都有另一个ObvervableCollection<testData>

了解每个testData我希望ListItem包含testItemtestData的一些数据。目前我将ObservableCollection<testItem>设置为列表的ItemsSource,但我只获得itemsData的第一项。

我该怎么办?

更新:

XAML:

<ListBox Name="ResultList" ItemsSource="{Binding TankstellenItem}" >
 <ListBox.ItemTemplate>
   <DataTemplate>
     <Border BorderBrush="#FF3AACDF" BorderThickness="4">
       <StackPanel Orientation="Horizontal" 
                   Background="White" 
                   UseLayoutRounding="True" Tap="ItemIsClicked">
        <StackPanel Width="130" Orientation="Vertical" Margin="0,0,0,0">
            <Border BorderThickness="2" 
                    Background="#FF3AACDF" BorderBrush="White">
                   <TextBlock Text="{Binding PriceBigDigits}" 
                              FontFamily="Assets/Font.ttf#LCD" 
                              FontSize="25" TextAlignment="Center" />
            </Border>
           <TextBlock Text="{Binding FuelType}" 
                       TextAlignment="Center" 
                       FontSize="15" Foreground="Black"/>
           <TextBlock Text="{Binding UpdateDate}" 
                      TextAlignment="Center" 
                      FontSize="15" Foreground="Black" />
           <TextBlock Text="{Binding DistanceString}" 
                      TextAlignment="Center" 
                      FontSize="15" Foreground="Black"/>
       </StackPanel>
      <StackPanel Orientation="Vertical" Margin="10,0,0,0" Width="400">
         <TextBlock Text="{Binding Title}" 
                    FontSize="30" FontWeight="Bold" Foreground="Black"/>
         <TextBlock Text="{Binding Address}" FontSize="20" Foreground="Black" />
         <TextBlock Text="{Binding PLZCity}" FontSize="20" Foreground="Black" />
       </StackPanel>
  </StackPanel>
   </Border>
   </DataTemplate>
   </ListBox.ItemTemplate>
</ListBox>

比我有testItem:

public testItem{
DistanceString (string),
Title (string),
Addresse (string),
PLZCity (string),
itemDates (ObservableCollection<itemData>)}

并且itemData:

public itemData{
PriceBigDigits (string),
FuelType (string),
UpdateDate (string)

1 个答案:

答案 0 :(得分:1)

如果我理解正确,您可能希望将itemDates绑定到ItemsControl的{​​{1}}属性。因此,请将第二个ItemsSource包裹在StackPanel的{​​{1}}内。