Showing different toolbar buttons on each page with Xamarin Forms

前端 未结 2 1707
时光取名叫无心
时光取名叫无心 2021-01-13 17:21

I have 2 pages in my Xamarin Forms app. My first page has 4 icons in the toolbar. My second page is a login page and has a tick and a cross in the toolbar.

I can\'t

2条回答
  •  广开言路
    2021-01-13 17:46

    One thing you could try is to keep your Login Page inside of a NavigationPage, and then instead of running PopAsync() within the Login Page after they have logged in successfully, simply replace the MainPage with your old Navigation page:

    In your App class:

    public NavigationPage AppNavPage = new NavigationPage(new FirstPage());
    
    public App() {
        MainPage = AppNavPage;
    }
    

    In your FirstPage:

    private async void ShowLoginPage() {
        ToolbarItems.Clear();
        var page = new NavigationPage(new LoginPage());
        await Navigation.PushAsync(page);
    }
    

    In Login Page:

    private async void OnCreateClicked(object sender, EventArgs e) {
        bool loginInfoIsGood = CheckLoginInfo(); //Check their login info
    
        if(loginInfoIsGood) {
            Application.Current.MainPage = App.AppNavPage;
        }
    }
    

    Otherwise, I have also done a custom renderer for the NavigationRenderer on iOS to insert toolbar items onto the right side of the Navigation Bar and have overridden some Menu related stuff on Android to change the icon text/colors.

提交回复
热议问题