是否可以在另一个列表框中制作列表框?两个列表框都绑定了相同的数据,只有第二个列表框添加了一些东西。我不知道只有第二个列表框(内部第一个)中的数据没有显示或绑定不起作用我不知道。第一个列表框的数据绑定OK。我的样本:
<Grid Grid.Row="2">
<ListBox x:Name="lbTransitNow" FontSize="13" ItemsSource="{Binding MyDataForTransit}">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate >
<StackPanel>
<Grid x:Name="gridTodayBtn">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock x:Name="tbTransitStart" Foreground="Black" Grid.Column="0"
Text="{Binding Lines_departure_time}" HorizontalAlignment="Left"/>
<TextBlock x:Name="tbTransitEnd" Foreground="Black" Text="{Binding Lines_arrival_time}"
Grid.Column="1"/>
<TextBlock x:Name="tbTransitTravelTime" Foreground="Black" Text="{Binding Lines_travelTime}"
Grid.Column="2"/>
<TextBlock x:Name="tbPrice" Foreground="Black" Text="{Binding Lines_price}"
Grid.Column="3"/>
<TextBlock x:Name="tbTransitKm" Foreground="Black" Text="{Binding Lines_km}"
Grid.Column="4"/>
<TextBlock x:Name="tbTransitNumber" Foreground="Black" Text="{Binding Lines_name}"
Grid.Column="5"/>
<Image x:Name="imgMoreInfo" Source="layoutGraphics/b5.png" Grid.Column="6" Width="40" Height="40" Tapped="imgMoreInfo_Tapped" Tag="{Binding}"></Image>
<ListBox x:Name="lbTransitNowSub" FontSize="13" ItemsSource="{Binding MyDataForTransit}">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate >
<Grid x:Name="gridTodayBtn">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock x:Name="tbTransitStart" Foreground="Black" Grid.Column="0"
Text="{Binding Lines_departure_time}" HorizontalAlignment="Left"/>
<TextBlock x:Name="tbTransitEnd" Foreground="Black" Text="{Binding Lines_arrival_time}"
Grid.Column="1"/>
<TextBlock x:Name="tbTransitTravelTime" Foreground="Black" Text="{Binding Lines_travelTime}"
Grid.Column="2"/>
<TextBlock x:Name="tbPrice" Foreground="Black" Text="{Binding Lines_price}"
Grid.Column="3"/>
<TextBlock x:Name="tbTransitKm" Foreground="Black" Text="{Binding Lines_km}"
Grid.Column="4"/>
<TextBlock x:Name="tbTransitNumber" Foreground="Black" Text="{Binding Lines_name}"
Grid.Column="5"/>
<Image x:Name="imgMoreInfo" Source="layoutGraphics/b5.png" Grid.Column="6" Width="40" Height="40" Tapped="imgMoreInfo_Tapped" Tag="{Binding}"></Image>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
public ObservableCollection<BindingData> _myDataForTransit = new ObservableCollection<BindingData>();
public ObservableCollection<BindingData> MyDataForTransit
{
get { return _myDataForTransit; }
set { _myDataForTransit = value; }
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(null, new PropertyChangedEventArgs(propertyName));
}
}
_myDataForTransit.Add(new BindingData
{
myData...
});
}
OnPropertyChanged("MyDataForTransit");