【发布时间】: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