我有一个ObservableCollection<testItem>
,每个testItem
都有另一个ObvervableCollection<testData>
。
了解每个testData
我希望ListItem
包含testItem
和testData
的一些数据。目前我将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)
答案 0 :(得分:1)
如果我理解正确,您可能希望将itemDates
绑定到ItemsControl
的{{1}}属性。因此,请将第二个ItemsSource
包裹在StackPanel
的{{1}}内。