如何在Xamarin.Forms中嵌套Tab视图

问题描述 投票:0回答:1

我正在尝试在Xamarin XAML中创建此布局,但是我不知道如何在TabView中组合TabView。我想要底部有3个主要标签,每个页面有1-2个子标签。在每个子选项卡上,我将需要一个带有列表项的ScrollView(我认为这是要使用的正确元素),这使其变得更加复杂。像这张照片:

enter image description here

关于实现此目标的任何想法或指导?

xaml xamarin mobile xamarin.forms xamarin.android
1个回答
0
投票

我正在尝试在Xamarin XAML中创建此布局,但是我不知道如何在TabView中组合TabView。

如果您要这样做,可以在[选项卡式]页面中嵌套TabView

TabViewhttps://github.com/chaosifier/TabView

在视图文件夹中创建三个选项卡页。

标签页:

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage
x:Class="TabbedPageDemo.MainPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:Views="clr-namespace:TabbedPageDemo.Views"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
BarBackgroundColor="Blue"
BarTextColor="White"
mc:Ignorable="d">

<Views:Tab1_Page Title="TAB1" />
<Views:Tab2_Page Title="TAB2" />
<Views:Tab3_Page Title="TAB3" />

</TabbedPage>

然后在您的tab1页面中使用TabView。

Tab1_Page:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="TabbedPageDemo.Views.Tab1_Page"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:local="clr-namespace:Xam.Plugin.TabView;assembly=Xam.Plugin.TabView"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<ContentPage.Content>
    <local:TabViewControl>
        <local:TabViewControl.ItemSource>
            <local:TabItem HeaderText="SUBTAB1">
                <StackLayout VerticalOptions="Start" Padding="10">
                    <Button
                    BackgroundColor="White"                    
                    Text="List Item"
                    TextColor="Black"/>
                </StackLayout>                                                
            </local:TabItem>
            <local:TabItem HeaderText="SUBTAB2">
                <Image Source="pink.jpg" />
            </local:TabItem>
        </local:TabViewControl.ItemSource>
    </local:TabViewControl>
</ContentPage.Content>
</ContentPage>

[请注意,如果要在底部的选项卡式页面中创建选项卡。在您的MainPage中添加以下代码。

 On<Android>().SetToolbarPlacement(ToolbarPlacement.Bottom);

enter image description here

[您可以从GitHub的TabbedPage_NestedTabView / TabbedPageDemo下载代码示例。https://github.com/WendyZang/Test.git

© www.soinside.com 2019 - 2024. All rights reserved.