question

EmilAlipiev-5934 avatar image
0 Votes"
EmilAlipiev-5934 asked ColeXia-MSFT commented

Xamarin.forms shell navigate to basic page, no flyout, no tabpage

I want to have simple page routing on my appshell, no flyout, no tabbedpage etc. Is it not posible?

when i define

<ShellItem
Title="LoginPage"
FlyoutItemIsVisible="False"
Route="login">
<ShellContent ContentTemplate="{DataTemplate local:LoginPage}" />
</ShellItem>

like above, it displays a 1 item flyout menu. why? i am not defining a FlyoutItem. Is there a way to achieve this using

MainPage = new AppShell();

or should i use classic way

MainPage = new LoginPage();

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ColeXia-MSFT avatar image
1 Vote"
ColeXia-MSFT answered ColeXia-MSFT commented

Hello,

Welcome to Microsoft Q&A!

In shell project even a simply ShellContent will be wrapped inside flyout menu .

The best way is to set LoginPage as MainPage in App af frist .

And then change the MainPage to AppShell after login successfully .


Update



Just a simple sample

Route

static class Route
    {
        private static Dictionary<string,Type> dic = new Dictionary<string, Type>();

        public static void RegisterRoute(string path , Type type)
        {
            if (path == null || path.Length == 0) return;

            dic[path] = type;
        }

        public static void GoToAsync(string page)
        {
            if (dic[page] == null)
            {
                //invalid page
                return;
            }

            var _p = Activator.CreateInstance(dic[page]) as Page;

            if (App.Current.MainPage == null)
            {               
                App.Current.MainPage = new NavigationPage(_p);
                return;
            }

            App.Current.MainPage.Navigation.PushAsync( _p,true);
        }
    }


App

public App()
        {
            InitializeComponent();

            Route.RegisterRoute("login", typeof(LoginPage));
            Route.RegisterRoute("login/main", typeof(MainPage));

            Route.GoToAsync("login");

        }


LoginPage

private void Button_Clicked(object sender, EventArgs e)
        {
            Route.GoToAsync("login/main");
        }



Best Regards,
Cole Xia


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

thats fine but when i set AppShell after Loginpage, it will be again a flyout menu right? I want LoginPage -> MainPage.. so main page is also a simple contentpage, not menu, no tabbed.
So it doesnt make sense to use Shell at all? because I like and prefer to use shell routings instead of classic navigations.

0 Votes 0 ·

Yes, you're right , if your app is full of simple contentpage and just has single navigation , it's no need to use shell at all .

For shell routings you can try to achieve it with your own implementation , it's not difficulty.

You can check my sample in above answer .



0 Votes 0 ·