I'm new to Xamarin forms and I have this requirement of creating the login page which logs two user types (Customer , Admin).
and after that it logs users to their profile .
the problem is each profile have a different flyout items .
so I have no idea how to achieve this and what is the best practice .
to demonstrate the idea here is a picture.
Asked
Active
Viewed 895 times
0

Abanoub Refaat
- 29
- 8
-
Take a look at https://stackoverflow.com/a/65187674/5228202 create other properties like IsAdmin and handle visibility by binding to IsVisible on the same appshell – Cfun Oct 27 '21 at 16:35
2 Answers
0
In your Login Button, you can do like this in XAML:
<Button ... Clicked="Login_Clicked" ... />
for this username you can check in your db if is admin or customer and return a value to know it. Create two pages (AdminPage and CustomerPage), and in your code-behind:
private async void Login_Clicked(object sender, System.EventArgs e)
{
if (Database.CheckUser() == "admin"){
Application.Current.MainPage.Navigation.PushAsync(new AdminPage());
} else {
Application.Current.MainPage.Navigation.PushAsync(new CustomerPage());
}
}
IF you don't want to create two pages, you can create one page (UserPage), passing the verification of what user is, and then in your code-behind you can set the buttons/labels and their functions, e.g:
UserPage.xaml.cs
public UserPage(string checkUser){
if(checkUser == "admin"){
ProcessAdmin();
}
else{
ProcessCustomer();
}
}
ProcessAdmin(){
btn1.Text = "Admin Profiler";
btn2.Text = "Home Page";
...
...
btn1.Clicked => (s,e) {
//do something for admin profiler button
};
}

techie
- 463
- 4
- 17
0
There are two kinds of page in FlyoutPage:Flyout and Detail,so you can change them depends on the role of users. Here is a example:
**FlyoutPage:**set the flyout depends on the flag set in the constructor
public partial class FlyoutMainPage : FlyoutPage
{
public FlyoutMainPage(bool flag)
{
InitializeComponent();
if (flag)
{ Flyout = new MenuPage1();
Detail = new NavigationPage(new TestPage1());
}
else
Flyout = new MenuPage2();
Detail = new NavigationPage(new TestPage1());
}
}
}
Navigate:set flag value based on action
async void Button_Clicked(System.Object sender, System.EventArgs e)
{
await Navigation.PushAsync(new FlyoutMainPage(true));
}
async void Button_Clicked_1(System.Object sender, System.EventArgs e)
{
await Navigation.PushAsync(new FlyoutMainPage(false));
}
}

Adrain
- 1,946
- 1
- 3
- 7