Forum Xamarin Xamarin.Forms

Can't change App Shell Tab to Navigation Page

iooovoltsiooovolts Member ✭✭✭
edited October 2019 in Xamarin.Forms

Does anyone know how I can make a Tab a NavigationPage? Basically the problem I have is that I have a view I navigate to from one of the Xamarin Shell tabs.
I am using Prism Mvvm so I have OnNavigatedTo() in the view I navigate to passing an object so I can populate the view. This method is never called because the Xamarin Shell Tab is not wrapped in a NavigationPage. As these tabs are created in AppShell.xaml I do not know how to do this.

Any help is much appreciated, thanks!

AppShell.xaml Tab page sample

<Tab x:Name="TestView" Title="Home" Icon="test.png">
            <ShellContent ContentTemplate="{DataTemplate local:TestView}" Style="{StaticResource BaseStyle}"/>
</Tab>

I have tried:

AppShell.xaml with NavigationPage

        <Tab x:Name="TestView" Title="Home" Icon="test.png">
            <ShellContent>
                <NavigationPage>
                    <x:Arguments>
                        <local:HomeView/>
                    </x:Arguments>
                </NavigationPage>
            </ShellContent>
        </Tab>

Best Answer

  • iooovoltsiooovolts Member ✭✭✭
    Accepted Answer

    @Angelru9 i figured since I was using the Prism MVVM framework I would use their NavigationService. The issue is currently fixed, its a shame though because I do not remember what I did now to resolve it. Thanks everyone!

Answers

  • wlchoy96wlchoy96 Member ✭✭✭

    What do you mean by navigation page? Is it other content page or shell content?

  • iooovoltsiooovolts Member ✭✭✭

    @wlchoy96 I mean NavigationPage as in how you wrap your pages in a navigation page so you can navigate from those pages. Thanks

  • NMackayNMackay GBInsider, University admin
    edited October 2019

    Prism 7.2 doesn't officially support shell AFAIK.

    Shell support might be appearing in 7.3, you'd have to ask the team. It sort of works from what I read but there are blocking issues in Forms, see this PR.

    https://github.com/PrismLibrary/Prism/issues/1809

    You should really ask this question on the Prism slack channel

  • wlchoy96wlchoy96 Member ✭✭✭

    Can you explain more on why you need the navigation page in your shell content?

  • iooovoltsiooovolts Member ✭✭✭

    @wlchoy96 sure thing!. Basically, I have a PopUp page (Rg.PopUp.Plugins) I navigate to using Prism NavigationService. The issue I am having is that the pages OnNavigatedTo() is not executed. So I thought maybe my Shell Tab had to be wrapped in a NavigationPage for this to work.

    However, I have now discovered that the constructor does not execute either so there is another issue at work.

    • I can confirm my view is registered for navigation.
    • I can also confirm my view references Prism and had viewmodellocation set to true
  • NMackayNMackay GBInsider, University admin

    @iooovolts said:
    @wlchoy96 sure thing!. Basically, I have a PopUp page (Rg.PopUp.Plugins) I navigate to using Prism NavigationService. The issue I am having is that the pages OnNavigatedTo() is not executed. So I thought maybe my Shell Tab had to be wrapped in a NavigationPage for this to work.

    However, I have now discovered that the constructor does not execute either so there is another issue at work.

    • I can confirm my view is registered for navigation.
    • I can also confirm my view references Prism and had viewmodellocation set to true

    See my comment about Prism support for Shell.

  • iooovoltsiooovolts Member ✭✭✭

    @NMackay thanks! I will definitely join the Slack channel. I'm sure it will come in handy for future issues. I've had a look at the post too :smile:

  • iooovoltsiooovolts Member ✭✭✭

    @NMackay can you please give me a link to the prism slack channel? I can't seem to find it, thanks!

  • NMackayNMackay GBInsider, University admin

    I'll DM you the link, I'll ask the maintainers permission before updating this thread

  • iooovoltsiooovolts Member ✭✭✭

    @NMackay thanks a lot!

  • Angelru9Angelru9 ESMember ✭✭✭

    @iooovolts Why not use shell navigation? Did you use prism navigation? Might be interested

  • iooovoltsiooovolts Member ✭✭✭
    Accepted Answer

    @Angelru9 i figured since I was using the Prism MVVM framework I would use their NavigationService. The issue is currently fixed, its a shame though because I do not remember what I did now to resolve it. Thanks everyone!

  • Angelru9Angelru9 ESMember ✭✭✭

    @iooovolts But do you use the Xamarin Form Shell and then navigate with the NavigationService prism framework?

  • iooovoltsiooovolts Member ✭✭✭

    @Angelru9 yes thats exactly what I do, it works for the most part :smile: the only issue is OnAppearing() not being executed, but thats currently an Open issue on GitHub

  • Angelru9Angelru9 ESMember ✭✭✭

    @iooovolts Can you show me a brief example? I just want to use the shell bar tab, but from inside the tab I want to navigate using prism, the OnNavigatedTo events don't work?

  • iooovoltsiooovolts Member ✭✭✭
    edited November 2019

    @Angelru9 so lets assume ViewA is one of your views represented as a tab using new AppShell(). You will have :

    await _navigationService.NavigateAsync("ViewB"); somewhere in your ViewAViewModel

    Now what you would need is for ViewB to inherit INavigatedAware so:

    public class ViewBViewModel : INavigatedAware
    {
        public ViewBViewModel() {}
        public override void OnAppearing()
        {
            //some code
        }
    }
    

    The OnAppearing method should be executed everytime you navigate to the page using Prisms INavigationService

Sign In or Register to comment.