【问题标题】:Xamarin C# - is using navigation page or ListView in the TabbedPageXamarin C# - 在 TabbedPage 中使用导航页或 ListView
【发布时间】:2019-03-21 04:46:16
【问题描述】:

image

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

【问题讨论】:

  • 我已经浏览了微软的文档。这对我的问题没有帮助。

标签: c# listview xamarin navigation tabbedpage


【解决方案1】:

1.创建一个Tabbed Page并将其设置为app的mainPage。

在 App.xaml.cs 中

public App()
{
   InitializeComponent();

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

2.将contentPage放在包含listview的Tabbed Page中。

例如,我把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>

在 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.当您单击列表视图的项目时,导航到包含您的其他列表视图的新内容页面

在 MainPage.xaml.cs 中

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

【讨论】:

  • 您好,但是如何在列表视图中的每个单元格上显示右箭头?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-11
  • 2015-12-07
  • 2020-06-12
  • 1970-01-01
  • 2018-08-03
  • 1970-01-01
相关资源
最近更新 更多