I have a ContentPage in Xamarin that I load from another page, with arguments.
await Navigation.PushAsync(new AnnouncementPage(verificationToken, sessionID, authenticationToken));
And here is AnnouncementPage.xaml.cs:
public partial class AnnouncementPage : ContentPage
{
private string _verificationToken;
private string _sessionID;
private string _authenticationToken;
public AnnouncementPage()
{
InitializeComponent();
}
public AnnouncementPage(string verificationToken, string sessionID, string authenticationToken)
{
BindingContext = new AnnouncementViewModel();
_verificationToken = verificationToken;
_sessionID = sessionID;
_authenticationToken = authenticationToken;
GetAnnouncements();
InitializeComponent();
}
// Other code
private void Announcement_Tapped(object sender, EventArgs e)
{
Console.WriteLine(_verificationToken.ToString());
}
}
Why does Announcement_Tapped throw a NullReferenceException? I am sure that _verificationToken is not null (at least in other parts of the code) as I use _verificationToken in GetAnnouncements(). I have searched everywhere about this issue and their code structure is the same as mine. My only guess is that this has to do with the AnnouncementPage() default constructor having no arguments. Any help would be appreciated.