1
votes

I am using the default MasterDetailPage navigation in my Xamarin app, where master is the side navigation and the detail are the contentpages the user can navigate to.

I already added the code to the MenuPage:

public MenuPage()
        {
            InitializeComponent();


            if (ProfilPage.loggedin)
            {
                ucet_stack.IsVisible = true;
                ucet.IsVisible = true;
                ucet.Text = "Váš účet " + ProfilPage.meno;
            }
            else
            {
                ucet_stack.IsVisible = false;
                ucet.IsVisible = false;
            }
        }

I want to change the content of the MenuPage after the user logs in. Constructor is only called the first time so it never changes. I tried to put the same code in onAppearing but didnt work either. So what could I use to dynamically change the menu after the user logs in? Note I am pretty new to this.

UPDATE:

I created a second MasterDetailPage with new MenuPage and tried to change it in a contentpage which is detail, but it went blank

 if(ProfilPage.loggedin)
        {
            Application.Current.MainPage = new MainLoggedPage();
        } 
2
your login logic will need to call a method that updates your Menu. There is nothing built in to XF that will do this for you.Jason
so lets say in the MenuPage I creat a method to reinitilaze the components with my new layout and can I call it from a detailpage like var m = new MenuPage; m.method(); to update it? or if I choose the approach to create 2 master pages how can I switch master from a detail´s content page?Chris Fodor
that is just creating a new instance of MenuPage and modifying it - you want to modify the instance that already exists and is visibleJason

2 Answers

1
votes

first, get a reference to your current MenuPage

var md = (MasterDetailPage)Application.Current.MainPage;
var menu = (MenuPage)md.Master;

then, call whatever public method you've created to update it

menu.SetUserLogin();
0
votes

I would say that this is the user interface problem and that you most likely don't need the hamburger menu displayed on the log in page as I am not aware that any app does have that.

But in the case you need it, the simplest and even the cleanest solution is to have two different master detail pages and assign them to the root depending on the situation.

It isn't impossible to hide parts of the master page, but as @Jason said it isn't a general practice to do that and i am not aware of examples for that, especially that you don't use MVVM and most Xamarin apps are done that way, you will mostly have to do it yourself and his suggestion on where to start is a good one.