我在第一页上有一个带有汽车对象的清单 . 我想从列表中点击一辆汽车,然后单击一个按钮,将所选汽车发送到另一个uwp页面上的列表 .
我试图将 listCar.selecteditems
放在我创建的名为 purchase
的空列表中,并在第2页显示 purchase
. 使用我目前的代码,它只在第2页的列表中显示 ProjectName_Car
.
任何正确显示这一点的帮助表示赞赏 .
Page1.xaml.cs
private void Add_Click(object sender, RoutedEventArgs e)
{
var query = listCars.SelectedItems.ToList().Cast<Car>();
foreach (var item in query)
{
purchase.Add(item);
}
liistCar.ItemsSource = purchase;
Frame.Navigate(typeof(Page2), listCar.Items);
}
Page2.xaml.cs
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
lstCars.ItemsSource = e.Parameter as List<Car> ;
}
编辑:Page1.xaml
<ListBox Name="listCars" ItemsSource="{x:Bind cars}" >
<ListBox.ItemTemplate>
<DataTemplate x:DataType="Car">
<StackPanel Padding="20">
<Image Width="200" Height="150" HorizontalAlignment="Left" Source="{x:Bind imgCar}" />
<TextBlock FontSize="22" HorizontalAlignment="Left" Text="{x:Bind Name}" Style="{StaticResource HeaderTextBlockStyle}"/>
<TextBlock FontSize="16" HorizontalAlignment="Left"> € <Run Text="{Binding Price}" /></TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
1 回答
这个将您选择的汽车列表对象作为参数传递给下一页及其所有属性 .
MainPage.xaml中
MainPage.xaml.cs中
Page2.xaml
Page2.xaml.cs