如何在Xamarin Forms中将TabbedPage添加到ContentPage中

4
我尝试将TabbedPage添加到内容页中,但它没有显示任何UI。我还试图寻找解决方案,但是得到的答复是:我们不能在ContentPage内放置TabbedPage,因为TabbedPage视图应该是父视图。
这里有一个ContentPage内部有两个选项卡的截图(链接),我想用TabbedPage替换它们。
但是我必须满足这样的要求,在Recent和All的位置上添加TabbedPage。如果有任何想法,请告诉我更新。

请在发布问题之前先阅读自己的问题。 - Ajil O.
你得到答案了吗?请告诉我们。我也在处理同样的问题。 - Sandeep Manmode
2个回答

1
如果你正在使用XAML,这个例子可能对你有用:
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             prism:ViewModelLocator.AutowireViewModel="True"
             xmlns:controls="clr-namespace:XLabs.Forms.Controls;assembly=XLabs.Forms"
             xmlns:me="clr-namespace:TabPages;assembly=TabPages"
             x:Class="YourApp.YourPage" BarBackgroundColor="#FF0000">
    <ContentPage Title="Tab 1">
        <StackLayout Padding="4">
            <!-- Content of the first tab -->
        </StackLayout>
    </ContentPage>
    <ContentPage Title="Tab 2">
        <StackLayout Padding="4">
            <!-- Content of the second tab -->
        </StackLayout>
    </ContentPage>
</TabbedPage>

2
谢谢您的回复,我想在ContentPage中添加TabbedPage。 - Dheeraj kushwaha
你需要将“ContentPage”更改为“TappedPage”。 - TeoVr81

-1

很难理解你的问题。我的英语不太好,我认为我没有理解你的问题。

顺便说一下,无法将TabbedPage添加到ContentPage中。您必须将ContentPage添加到TabbedPage中。

例如(来自Xamarin文档)

public class MainPageCS : TabbedPage {   public MainPageCS ()   {
    var navigationPage = new NavigationPage (new SchedulePageCS ());
    navigationPage.Icon = "schedule.png";
    navigationPage.Title = "Schedule";

    Children.Add (new TodayPageCS ());
    Children.Add (navigationPage);   } }

TabbedPage中填充了两个子页面对象。第一个子页面是ContentPage实例,第二个选项卡是包含ContentPage实例的NavigationPage。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接