【问题标题】:Cross-platform pager with xamarin.form使用 xamarin.form 的跨平台寻呼机
【发布时间】:2019-07-10 02:38:30
【问题描述】:

在 Xamarin.Android 中,它有一个名为 ViewPager 的类来支持“手势导航允许用户左右滑动以逐步浏览数据页面”。 (https://docs.microsoft.com/en-us/xamarin/android/user-interface/controls/view-pager/)

但我的任务是为 Android 和 iOS 编写跨平台代码(无需为此手势重写新代码)。使用 Xamarin.Form 是否有任何库支持此功能?我读过 Xamarin.Form 轮播,但它似乎用于幻灯片,不适合新闻列表。

【问题讨论】:

    标签: xamarin xamarin.forms


    【解决方案1】:

    我觉得TabbedPage更适合你。 tabbedPage 支持手势导航,允许用户左右滑动浏览数据页面,只需将不同页面的数据设置在不同的选项卡中即可。

    这里正在运行 GIF。

    你可以像下面的代码一样添加这个标签页。

    <TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:local="clr-namespace:TabbedPageDemo;assembly=TabbedPageDemo"
            x:Class="TabbedPageDemo.TabbedPageDemoPage">
           <TabbedPage.Resources>
              <ResourceDictionary>
               <local:NonNullToBooleanConverter x:Key="booleanConverter" />
              </ResourceDictionary>
           </TabbedPage.Resources>
            <TabbedPage.ItemTemplate>
              <DataTemplate>
               <ContentPage Title="{Binding Name}" Icon="monkeyicon.png">
                 <StackLayout Padding="5, 25">
                  <Label Text="{Binding Name}"
                  Font="Bold,Large"
                  HorizontalOptions="Center" />
                  <Image Source="{Binding PhotoUrl}"
                    WidthRequest="200" 
                    HeightRequest="200" />
          <StackLayout Padding="50, 10">
            <StackLayout Orientation="Horizontal">
              <Label Text="Family:"
                     HorizontalOptions="FillAndExpand" />
              <Label Text="{Binding Family}"
                     Font="Bold,Medium" />
            </StackLayout>
            <StackLayout Orientation="Horizontal"
                         IsVisible="{Binding Subfamily,
                            Converter={StaticResource booleanConverter}}">
              <Label Text="Subfamily:"
                     HorizontalOptions="FillAndExpand" />
              <Label Text="{Binding Subfamily}"
                     Font="Bold,Medium" />
            </StackLayout>
            <StackLayout Orientation="Horizontal"
                         IsVisible="{Binding Tribe,
                            Converter={StaticResource booleanConverter}}">
              <Label Text="Tribe:"
                      HorizontalOptions="FillAndExpand" />
              <Label Text="{Binding Tribe}"
                     Font="Bold,Medium" />
            </StackLayout>
            <StackLayout Orientation="Horizontal">
              <Label Text="Genus:"
                     HorizontalOptions="FillAndExpand" />
              <Label Text="{Binding Genus}"
                     Font="Bold,Medium" />
            </StackLayout>
          </StackLayout>
          </StackLayout>
         </ContentPage>
       </DataTemplate>
      </TabbedPage.ItemTemplate>
    </TabbedPage>
    

    您可以在标签页中添加不同的ItemTemplate。 这是一个相关链接。 https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/tabbed-page

    更新:你可以像下面的GIF一样在tabbpage中添加listview。

    【讨论】:

    猜你喜欢
    • 2011-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-14
    • 2019-01-29
    • 1970-01-01
    • 1970-01-01
    • 2022-08-22
    相关资源
    最近更新 更多