开发者

How to reach ApplicationBar from PopUp window?

I'm trying to protect my app with password. I've chosen a PopUp window in which user can 开发者_开发技巧enter their password.

My app contains ApplicatioBar so I need to hide it when password input dialog is shown. I do as follows:

public MainPage() 
{
    ...
    PasscodeApplicationBarVisibility(); //Now AppBar disapears
    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;

        //Here is the problem - NullReferenceException
        PasscodeApplicationBarVisibility();

        ((PasswordInputPrompt)sender).Completed -= passwordInput_Completed; }
    else { 
        ((PasswordInputPrompt)sender).Completed -= passwordInput_Completed; 
        IncorrectPasscode = true; 
        PasscodeEvent(); }          
}

ApplicationBar disappears as should be. When user enters a valid password the app should show the ApplicationBar. But when I try to reach ApplicationBar from PopUp window I get NullReferenceException which is understandable because PopUp windows doesn't contain ApplicationBar. I don't know how to reach MainPage's ApplicationBar when PopUp window is open.

Please, any hints?

UPDATE:

Thank you guys for the answers. It was my foult that I didn't mention that PasswordInputPrompt is part of the Coding4Fun toolkit. I was certain that PasswordInputPrompt inherits from System.Windows.Controls.Primitives.PopUp. As you know it does not. Dennis Delimarsky's answer is right since using standard PopUp is taken into consideration.

Fortunately coders from the Coding4Fun project predicted the need of geting to Parent. In my case the answer is as follows: passwordInput.Parent.Dispatcher.BeginInvoke(PasscodeApplicationBarVisibility);


You can access the ApplicationBar by setting the Closed event handler:

Popup popup = new Popup();
// Add children to the Popup instance
popup.IsOpen = true;
popup.Closed += (s, ev) => 
{  
  ((ApplicationBar)ApplicationBar).IsVisible = true;
};


what exactly is the PasswordInputPrompt?

Usually in modal windows/popup's there is a Closed or Closing event which you could hook into at which point you can get access to the app bar easily.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜