首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TabbedPage中的xamarin mvvmcross

TabbedPage中的xamarin mvvmcross
EN

Stack Overflow用户
提问于 2020-12-10 03:26:57
回答 1查看 341关注 0票数 1

如何使用mvvmcross在xamarin表单的选项卡式页面中轻松实现选项卡式页面?

TabbedPage1;

代码语言:javascript
复制
 [MvxTabbedPagePresentationAttribute(Position = TabbedPosition.Root, WrapInNavigationPage = true, NoHistory = false)]
    public partial class TabbedPage1: MvxTabbedPage<ViewModels.TabbedPage1ViewModel>
    {
        public TabbedPage1()
        {
            InitializeComponent();
        }
    }

TempPage;

代码语言:javascript
复制
 [MvxTabbedPagePresentationAttribute(Position = TabbedPosition.Tab, Icon = "map_outline", WrapInNavigationPage = true, NoHistory = false)]
        public partial class TempPage: MvxContentPage<ViewModels.TempPageViewModel>
        {
            public TempPage()
            {
                InitializeComponent();
            }
        }

TabbedPage2;

代码语言:javascript
复制
 [MvxTabbedPagePresentationAttribute(Position = TabbedPosition.Root, WrapInNavigationPage = true, NoHistory = false)]
    public partial class TabbedPage2 : MvxTabbedPage<ViewModels.TabbedPage2ViewModel>
    {
        public TabbedPage2 ()
        {
            InitializeComponent();
        }
    }

我目前的情况是,tabbedpage2显示得像一个模式页面。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-11 16:27:13

您可以在选项卡式页面中嵌套一个TabView。通过NuGet安装Xam.Plugin.TabViewhttps://www.nuget.org/packages/Xam.Plugin.TabView

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

选项卡页:

代码语言:javascript
复制
<?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:

代码语言:javascript
复制
<?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中添加以下代码。

代码语言:javascript
复制
 On<Android>().SetToolbarPlacement(ToolbarPlacement.Bottom);

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65223593

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档