c# - 我如何控制列表视图项目的详细信息?
问题描述
我有 2 页有自己的列表视图。我需要将第一个列表视图项目的所有详细信息添加到另一个列表视图中。感谢您对我模糊的问题的任何帮助。
public async void OnTapped(object sender, ItemTappedEventArgs e)
{
await Navigation.PushAsync(new TeamPage());
}
因此,当一个项目被点击时,它会切换到另一个页面,但希望将所选项目添加到 TeamPage 列表视图中。项目的所有细节都绑定到一个 IList。
解决方案
根据您的描述,您想点击 ListView 项目,然后导航到另一个页面,在此页面列表视图中显示点击的项目,对吗?如果是,我会做一个样本,你可以看看:
第 1 页:
<StackLayout>
<ListView ItemsSource="{Binding model3s}" ItemTapped="ListView_ItemTapped">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal">
<Label Text="{Binding Id}" />
<Label Text="{Binding FirstName}" />
<Label Text="{Binding LastName}" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
public partial class Page11 : ContentPage
{
public ObservableCollection<model3> model3s { get; set; }
public Page11 ()
{
InitializeComponent ();
model3s = new ObservableCollection<model3>()
{
new model3(){Id=1,FirstName="Cherry",LastName="Bu",Description="Age is 28, class is A"},
new model3(){Id=2,FirstName="Barry",LastName="Bu",Description="Age is 32, class is B"},
new model3(){Id=3,FirstName="Wendy",LastName="Bu",Description="Age is 25, class is C"},
new model3(){Id=4,FirstName="Stnfan",LastName="Bu",Description="Age is 27, class is A"},
new model3(){Id=5,FirstName="Annie",LastName="Bu",Description="Age is 28, class is B"},
new model3(){Id=6,FirstName="Mattew",LastName="Bu",Description="Age is 25, class is C"},
new model3(){Id=7,FirstName="Amy",LastName="Bu",Description="Age is 29, class is A"},
new model3(){Id=8,FirstName="Elvis",LastName="Bu",Description="Age is 32, class is B"},
};
this.BindingContext = this;
}
private async void ListView_ItemTapped(object sender, ItemTappedEventArgs e)
{
var content = e.Item as model3;
await Navigation.PushModalAsync(new Page12(content));
}
}
public class model3
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Description { get; set; }
}
第2页:
<StackLayout>
<ListView x:Name="listview1" ItemsSource="{Binding collection}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal">
<Label Text="{Binding FirstName}" />
<Label Text="{Binding LastName}" />
<Label Text="{Binding Description}" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
public partial class Page12 : ContentPage
{
public ObservableCollection<model3> collection { get; set; }
public Page12 (model3 content)
{
InitializeComponent ();
collection = new ObservableCollection<model3>();
collection.Add(content);
this.BindingContext = this;
}
}
推荐阅读
- reactjs - 按 AZ 和 ZA MobX 排序
- java - Java 文件可执行文件,但命令行显示它不是有效的 win32 应用程序
- javascript - 匹配卡 - 卡无法正确显示
- flutter - Dart Future.wait 等待多个期货并返回不同类型的结果
- lua - 获取字符串匹配前后的字符
- python - 使用 sqlalchemy 将 sql 查询列值转换为列表
- twilio - 通过 REST 在 Twilio Chat 中上传媒体消息
- scala - Spark 写入配置单元作为 ORC 错误:路径不是文件
- powershell - 如何使用 Powershell 更改 Windows 10 中的电源计划并在长脚本后恢复为原始设置?
- android - 如何使用 Dagger2 for Android 提供 Room Dao 依赖项?