简体   繁体   English

Xamarin形成带有导航页面的iOS选项卡式页面

[英]Xamarin forms iOS tabbed page with navigation page

So, Xamarin advocates, and others, I invite you all to try and answer how can I have navigation page with tabbed page for iOS? 因此,Xamarin倡导者和其他一些人,我邀请大家尝试并回答如何为iOS提供带有选项卡式页面的导航页面?

Sounds pretty simple, does it not? 听起来很简单,不是吗? For android, no worries, no issues, nothing out of the ordinary, can customize anything I need. 对于android,无需担心,没有问题,没有什么不同寻常的,可以自定义我需要的任何东西。

For iOS on the other hand, despite me being told that I am the one who does not comprehend the practices of Xamarin (or in other words, the escape routes one needs to take in order for that to actually work), I can not have navigation page and tabbed page coexisting, without issues. 另一方面,对于iOS,尽管有人告诉我我是不了解Xamarin做法的人(换句话说,为了真正起作用,需要采取逃生路线),但我无法导航页面和选项卡式页面共存,没有问题。

Here is what happens: 这是发生了什么:

if (navigation page contains tabbed page)
{
    no title is shown in the navigation bar
}
else if (each content page for the tabbed page is contained in a navigation page)
{
    no icon or title is shown in the tab bar
}
else
{
    The company manager does not want any else, there has to be a navigation page to allow opening other pages from the contents in each tab, and there has to be tabbed page and navigation bar for iOS
}

Now the million dollar question as they say in USA: how can we solve this "mystery"? 现在,正如他们在美国所说的那样,百万美元的问题是:我们如何解决这个“谜”?

Thank you so much in advance, for all the answers and support (on using this sort of.. ah, tool, also known as Xamarin). 预先非常感谢您提供的所有答案和支持(使用这种.. ah工具,也称为Xamarin)。

So this is what I have done. 这就是我所做的。 In your App.cs (or main project class) you need to create a new NavigationPage that contains your TabbedPage, with the navigation controller you will have a navigation context and with that you can Push you next pages, if you don't want to have a navigation bar at the top you can push ModalPages or use NavigationPage.SetHasNavigationBar(this, false); 在您的App.cs(或主项目类)中,您需要创建一个新的NavigationPage,其中包含TabbedPage,使用导航控制器,您将拥有一个导航上下文,并且如果您不想这样做,则可以将您下一页推入页面在顶部有一个导航栏,您可以按ModalPages或使用NavigationPage.SetHasNavigationBar(this, false); ,code snippet: ,代码段:

public class App : Application
{
    public App ()
    {
        MainPage = new NavigationPage(new MainTabbedPage());
    }
}

public class MainTabbedPage : TabbedPage
{
    public MainTabbedPage()
    {
        Children.Add(new FirstPage());
        Children.Add(new SecondPage());
    }
}

public class SecondPage : ContentPage
{
    public SecondPage()
    {
        Title = "Second Page";

        var btn = new Button
        {
            Text = "Click me"
        };

        btn.Clicked += BtnBlicked;

        Content = btn;
    }

    async void BtnBlicked(object sender, EventArgs e)
    {
        await Navigation.PushAsync(new ThirdPage());
    }
}

public class ThirdPage : ContentPage
{
    public ThirdPage()
    {
        Title = "Third Page";
    }
}

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM