【问题标题】:Prism - Xamarin Forms: How to keep bottom tab active during navigationPrism - Xamarin Forms:如何在导航期间保持底部选项卡处于活动状态
【发布时间】:2018-11-18 01:30:06
【问题描述】:

我是一个 xamarin forms prism 应用程序,我有 3 个选项卡,并且选项卡栏仅在该特定页面上处于活动状态,如果我在特定选项卡中深入导航,则底部选项卡消失了。即使我们导航到这些选项卡内的其他页面,是否有办法保持底部选项卡处于活动状态?

我试图做类似this 的事情,但我无法在 prism 中做到这一点。

如果没有 prism,如上面的链接所示,这很简单,但我不喜欢使用 prism。谁能建议我如何实现它?

我的代码: App.Xaml.cs

protected override async void OnInitialized()
        {
            InitializeComponent();
            await NavigationService.NavigateAsync("NavigationPage/MainPage");
        }

MainPage.XML

<?xml version="1.0" encoding="UTF-8"?>
< TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
             xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core" 
             xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core" 
             xmlns:windows="clr-namespace:Xamarin.Forms.PlatformConfiguration.WindowsSpecific;assembly=Xamarin.Forms.Core"


             xmlns:local="clr-namespace:MyTabs.Common.Views"
             x:Class="MyTabs.Common.Views.MainPage" BackgroundColor="Olive" BarBackgroundColor="Maroon">
     <TabbedPage.Children>
     <local:PageOne Title="PageOne"
                         Icon="PageOne.png" />

    <local:PageTwo Title="PageTwo"
                         Icon="PageTwo.png" />

    <NavigationPage Title="PageThree" Icon="PageThree s.png">
        <x:Arguments> 
                    <local: PageThree/> 
        </x:Arguments>
        </NavigationPage>
    <local:PageFour Title="PageFour"
                         Icon="PageFour.png" />
    </TabbedPage.Children>
</TabbedPage>

PageThreeViewModel:

public class PageThreeViewModel : ViewModelBase
    {
        private ICommand pageFiveCommand;
        public ICommand PageFiveCommand { get { return pageFiveCommand; } }

        private void OnCloseCommand()
        {
            _navigationService.GoBackAsync();
        }

        public PageThreeCommand ViewModel()
        {
            pageFiveCommand = new DelegateCommand(OnPageFiveCommand);
        }

        private async void OnPageFiveCommand()
        {
            //await _navigationService.NavigateAsync(?NavigationPage/PageFive");
            await _navigationService.NavigateAsync("GiftCardPage");
        }
    }

【问题讨论】:

  • 您是否尝试过将选项卡内的页面设置为导航页面。这样标签就会一直存在
  • 我该怎么做?
  • 所以只有PageThree需要里面的导航?您可以将您在 Page3 中导航的代码粘贴到其他页面吗?您也可以尝试在 await NavigationService.NavigateAsync("NavigationPage/MainPage"); 中删除 NavigationPage;
  • 所有页面都需要它,但目前只是测试第三页。它只是一个空白页。没有在该页面中添加任何内容。
  • 你必须从 PageThreeViewModel 导航然后它应该工作。因为我也做了同样的事

标签: xamarin xamarin.forms


【解决方案1】:

您可以通过使用NavigationPageContentPage 包裹在TabbedPage 中来实现此目的。

代码

<TabbedPage>
    <TabbedPage.Children>
        <NavigationPage Title="Home" Icon="home.png">
            <x:Arguments>
                <ContentPage>
                    //Your ContentPage here
                    //You can have a ViewModel for this ContentPage and Navigate inside that and will still have the Tabbed Page outside.
                </ContentPage>
            </x:Arguments>
        </NavigationPage>
    </TabbedPage.Children>
</TabbedPage>

【讨论】:

  • 我尝试了代码&lt;x:Arguments&gt; &lt;local:NewsFeed/&gt; &lt;/x:Arguments&gt;,其中&lt;local:NewsFeed/&gt; 是内容页面,但是当我在NewsFeed 中导航时,标签不会停留在底部。
  • 你是如何在里面导航的?可以发一下代码吗?
猜你喜欢
  • 1970-01-01
  • 2021-01-30
  • 1970-01-01
  • 2018-04-08
  • 1970-01-01
  • 1970-01-01
  • 2021-11-17
  • 2021-03-15
  • 1970-01-01
相关资源
最近更新 更多