I am trying to password protect my application. I selected the PopUp window in which the user can enter his password.
My application contains ApplicatioBar, so I need to hide it when the password input dialog is displayed. I do the following:
public MainPage()
{
...
PasscodeApplicationBarVisibility();
PasscodeEvent();
}
private void PasscodeApplicationBarVisibility()
{
((ApplicationBar)ApplicationBar).IsVisible = !(settings.PasscodeRequired);
}
private void PasscodeEvent()
{
passwordInput = new PasswordInputPrompt {
Title = "Please Enter Passcode!",
InputScope = new InputScope { Names = { new InputScopeName() { NameValue = InputScopeNameValue.TelephoneNumber } } }, };
passwordInput.Completed += new EventHandler<PopUpEventArgs<string, PopUpResult>>(passwordInput_Completed);
passwordInput.Show();
}
void passwordInput_Completed(object sender, PopUpEventArgs<string, PopUpResult> e)
{
if (settings.Passcode.Equals(e.Result)) {
settings.PasscodeRequired = false;
PasscodeApplicationBarVisibility();
((PasswordInputPrompt)sender).Completed -= passwordInput_Completed; }
else {
((PasswordInputPrompt)sender).Completed -= passwordInput_Completed;
IncorrectPasscode = true;
PasscodeEvent(); }
}
ApplicationBar disappears as it should be. When the user enters a valid password, the application should show an ApplicationBar. But when I try to get to the ApplicationBar from the PopUp window, I get NullReferenceExceptionthat, which is understandable because the PopUp windows do not contain the ApplicationBar. I don't know how to get to MainPage ApplicationBar when the PopUp window is open.
Please any hints?
UPDATE:
, , . , , PasswordInputPrompt Coding4Fun. , PasswordInputPrompt System.Windows.Controls.Primitives.PopUp. , .
, PopUp.
, Coding4Fun Parent. : passwordInput.Parent.Dispatcher.BeginInvoke(PasscodeApplicationBarVisibility);