I have a MasterDetailPage. In my master page I am calling the OnAppearing method like so:
protected override async void OnAppearing()
{
List<MasterPageItem> menu = new List<MasterPageItem>();
var myValue = await SecureStorage.GetAsync("token");
if(myValue == null)
{
menu.Add(new MasterPageItem
{
Title = "Home",
TargetType = typeof(HomePage)
});
menu.Add(new MasterPageItem
{
Title = "Search Patients",
TargetType = typeof(PatientsPage)
});
menu.Add(new MasterPageItem
{
Title = "Search Professionals",
TargetType = typeof(ProfessionalsPage)
});
menu.Add(new MasterPageItem
{
Title = "Blog",
TargetType = typeof(BlogPage)
});
menu.Add(new MasterPageItem
{
Title = "Register",
TargetType = typeof(RegistrationPage)
});
menu.Add(new MasterPageItem
{
Title = "Login",
TargetType = typeof(LoginPage)
});
}
else
{
menu.Add(new MasterPageItem
{
Title = "Home",
TargetType = typeof(HomePage)
});
menu.Add(new MasterPageItem
{
Title = "Search Patients",
TargetType = typeof(PatientsPage)
});
menu.Add(new MasterPageItem
{
Title = "Search Professionals",
TargetType = typeof(ProfessionalsPage)
});
menu.Add(new MasterPageItem
{
Title = "Blog",
TargetType = typeof(BlogPage)
});
menu.Add(new MasterPageItem
{
Title = "Messages",
TargetType = typeof(MailboxPage)
});
menu.Add(new MasterPageItem
{
Title = "Account",
TargetType = typeof(AccountPage)
});
menu.Add(new MasterPageItem
{
Title = "Logout",
TargetType = typeof(LoginPage)
});
}
listView.ItemsSource = menu;
}
How ever it only gets called once when I goto the master page for the first time. I am looking for away to refresh my listView when someone logins or logouts.
I have tried the following on my LoginPage
protected async void OnLogin(System.Object sender, System.EventArgs e)
{
LoginClass response = await webService.LoginAsync(Email.Text, Password.Text);
var myValue = await SecureStorage.GetAsync("token");
Console.WriteLine(myValue);
if (response.error != null)
{
await DisplayAlert("Error", response.error, "OK");
}
else
{
await SecureStorage.SetAsync("token", response.token);
MasterPage masterPage = new MasterPage();
masterPage.createMenu();
}
}
and created a new method in my master page called createMenu and its being called, but my listView does not get updated and it should be the "token" has been created.
public async void createMenu()
{
List<MasterPageItem> menu = new List<MasterPageItem>();
var myValue = await SecureStorage.GetAsync("token");
if (myValue == null)
{
menu.Add(new MasterPageItem
{
Title = "Home",
TargetType = typeof(HomePage)
});
menu.Add(new MasterPageItem
{
Title = "Search Patients",
TargetType = typeof(PatientsPage)
});
menu.Add(new MasterPageItem
{
Title = "Search Professionals",
TargetType = typeof(ProfessionalsPage)
});
menu.Add(new MasterPageItem
{
Title = "Blog",
TargetType = typeof(BlogPage)
});
menu.Add(new MasterPageItem
{
Title = "Register",
TargetType = typeof(RegistrationPage)
});
menu.Add(new MasterPageItem
{
Title = "Login",
TargetType = typeof(LoginPage)
});
}
else
{
menu.Add(new MasterPageItem
{
Title = "Home",
TargetType = typeof(HomePage)
});
menu.Add(new MasterPageItem
{
Title = "Search Patients",
TargetType = typeof(PatientsPage)
});
menu.Add(new MasterPageItem
{
Title = "Search Professionals",
TargetType = typeof(ProfessionalsPage)
});
menu.Add(new MasterPageItem
{
Title = "Blog",
TargetType = typeof(BlogPage)
});
menu.Add(new MasterPageItem
{
Title = "Messages",
TargetType = typeof(MailboxPage)
});
menu.Add(new MasterPageItem
{
Title = "Account",
TargetType = typeof(AccountPage)
});
menu.Add(new MasterPageItem
{
Title = "Logout",
TargetType = typeof(LoginPage)
});
}
listView.ItemsSource = menu;
}
What am I doing wrong here? Or is there another way to go about this?