xamarin.forms - 我可以在标签页中使用 ClassId 来区分它们的内容吗
问题描述
我正在尝试将同一页面用于 TabbedPage 中的 3 个选项卡。但是每个选项卡必须在列表视图中显示不同的数据。有没有办法为每个选项卡设置一个参数?
例子
<local:Sales Title="Pending"
Icon="ic_shortcut_home.png"
ClassId="pending"/>
<local:Sales Title="Posted"
Icon="ic_shortcut_home.png"
ClassId="posted"/>
<local:Sales Title="Uploaded"
Icon="ic_shortcut_home.png"
ClassId="uploaded"/>
我尝试使用 ClassId 和 Title 来获得它们的区别,但是在 Sales 类构造函数中检索 ClassId 时遇到问题,还有其他方法可以获得我想要的输出吗?
public Sales()
{
InitializeComponent();
BindingContext = this;
salesCollection = new ObservableCollection<Head>();
initLvw();
Console.WriteLine(Title); //returns null
Console.WriteLine(ClassId); // returns null
}
解决方案
您可以在OnAppearing方法中加载数据:
protected override void OnAppearing()
{
base.OnAppearing();
Console.WriteLine(ClassId + "OnAppearing");
BindingContext = this;
salesCollection = new ObservableCollection<Head>();
initLvw();
}
delay
或者在构造函数中加载一点数据:
public AboutPage()
{
InitializeComponent();
Task.Run(async () =>
{
await Task.Delay(200);
Console.WriteLine(ClassId + "AboutPage");
BindingContext = this;
salesCollection = new ObservableCollection<Head>();
initLvw();
});
}
推荐阅读
- c++ - TaskScheduler-Library 的预处理不起作用 - 多定义错误
- android - Android P 阻止了相机访问
- android - 使用 Android Studio 颤振不显示设备列表
- r - 从网页到 R 的阅读表
- javascript - 如何将html符号从javascript发送到java
- java - 将 ByteBuffer 的内容写入 DataOutput?
- postgresql - Postgres:10 在 docker swarm 集群中。数据库系统已关闭
- java - 独立 Wildfly 的微配置文件实现
- javascript - javascript中的多个构造函数(重载)
- python - 如何在 Conv2D 层 Tensorflow 中获得步幅值?