所以我必须首次在C#中制作我的布局......
现在我希望能够在列表视图项目上进行选项卡,然后转到包含te tapped item数据的详细信息页面。我该怎么做?
我目前有这段代码;
public MainPage()
{
GeneratePage();
InitializeComponent();
}
private async Task GeneratePage()
{
List<Folder> folders = await ApiManager.GetFoldersAsync();
foreach (var f in folders)
{
List<Lists> lists = new List<Lists>();
foreach (int id in f.list_ids)
{
lists.Add(await ApiManager.GetSpecificListAsync(id));
// Debug.WriteLine("ID for list '"+ f.title +"' : " + id);
}
this.Children.Add(new ContentPage
{
Title = f.title,
Content = new ListView
{
ItemsSource = lists
}
});
}
}
答案 0 :(得分:2)
你有一个ContentPage列表?这很奇怪。但是,通常情况下,为ListView项添加一个tap事件,您订阅了ItemTapped
事件。
var list = new ListView();
list.ItemsSource = myItems;
list.ItemTapped += myEventTapped();
Content = list;`
答案 1 :(得分:2)
通常我使用XAML而不是CodeBehind来创建UI,但是下面的代码片段可以解决这个问题,但我还没有测试过。
只需附加到ItemTapped事件即可。或者,您也可以在ListView上添加TapGestureRecognizer。
private async Task GeneratePage()
{
List<Folder> folders = await ApiManager.GetFoldersAsync();
foreach (var f in folders)
{
List<Lists> lists = new List<Lists>();
foreach (int id in f.list_ids)
{
lists.Add(await ApiManager.GetSpecificListAsync(id));
// Debug.WriteLine("ID for list '"+ f.title +"' : " + id);
}
ListView listView = new ListView { ItemsSource = lists };
listView.ItemTapped += ListViewOnItemTapped;
this.Children.Add(new ContentPage
{
Title = f.title,
Content = listView
});
}
}
void ListViewOnItemTapped(object sender,ItemTappedEventArgs itemTappedEventArgs) { throw new NotImplementedException(); }