Xamarin C# - 在 TabbedPage 中使用导航页面或 ListView

Xamarin C# - is using navigation page or ListView in the TabbedPage

image

参考上图。它是一个有 4 个标签页的 TabbedPage。我可以知道我们如何执行此操作。当用户单击列表时,它将导航到一个新页面(在标签页之外)。然后,它可以在单击后退按钮时返回到 TabbedPage。 是用ListView还是导航页? 请指教。谢谢。

1.create一个标签页并将其设置为应用程序的主页面。

in App.xaml.cs

public App()
{
   InitializeComponent();

   MainPage = new NavigationPage(new MyTabbedPage());
}

2.Put 包含列表视图的标签页中的内容页。

比如,我把listview放到了MainPage里面。

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        xmlns:local="clr-namespace:App8"
         x:Class="App8.MyTabbedPage">
<!--Pages can be added as references or inline-->
  <ContentPage Title="Tab 1" Icon="xxx.png"/> //set the title and icon of toolbar item
  <local:MainPage Title="Tab 1" Icon="xxx.png"/>
  <ContentPage Title="Tab 1" Icon="xxx.png"/>
</TabbedPage>

in MainPage.xaml

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:local="clr-namespace:App8"
         x:Class="App8.MainPage">

<ListView  x:Name="listView" ItemTapped="ListView_ItemTapped" >
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell Height="30">
               ...
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

</ContentPage>

3.When 您单击列表视图的项目导航到包含您的其他列表视图的新内容页面

in MainPage.xaml.cs

private void ListView_ItemTapped(object sender, ItemTappedEventArgs e)
{
  Navigation.PushAsync(new xxxContentPage(),true);
}