Question

I am developing a Windows Phone 7.1 App and using PasswordInputPrompt control in Coding4fun library. I initialize the control and add an EventHandler for the Completed event and then display the control.

PasswordInputPrompt passwordInput = new PasswordInputPrompt
    {
        Title = "Application Password",
        Message = "Please Enter App Password",
    };
passwordInput.Completed += Pwd_Entered;
passwordInput.Show();

In the Completed event handler I check if the password is blank and if so then I would like to keep the prompt displaying.

    void Pwd_Entered(object sender, PopUpEventArgs<string, PopUpResult> e)
    {
        if (!string.IsNullOrWhiteSpace(passwordInput.Value))
        {
            //Do something
        }
        else
        {
            passwordInput.Show();  //This is not working. Is this the correct way???
        }
    }

The else part is not working. The prompt closes even if the entered password is blank. Can somebody show me the correct way of achieving this?

Was it helpful?

Solution

I did some quick testing with this and it seems to work. The source code for the control has

 public virtual void OnCompleted(PopUpEventArgs<T, TPopUpResult> result)
{
  this._alreadyFired = true;
  if (this.Completed != null)
    this.Completed((object) this, result);
  if (this.PopUpService != null)
    this.PopUpService.Hide();
  if (this.PopUpService == null || !this.PopUpService.BackButtonPressed)
    return;
  this.ResetWorldAndDestroyPopUp();
}

Implying that you can overwrite the method.

So, create a class that inherits from the control

public class PasswordInputPromptOveride : PasswordInputPrompt
{
    public override void OnCompleted(PopUpEventArgs<string, PopUpResult> result)
    {
        //Validate for empty string, when it fails, bail out.
        if (string.IsNullOrWhiteSpace(result.Result)) return;


        //continue if we do not have an empty response
        base.OnCompleted(result);
    }
}

In your code behind:

 PasswordInputPrompt passwordInput;

    private void PasswordPrompt(object sender, System.Windows.Input.GestureEventArgs e)
    {
        InitializePopup();
    }

    private void InitializePopup()
    {
        passwordInput = new PasswordInputPromptOveride
        {
            Title = "Application Password",
            Message = "Please Enter App Password",
        };

        passwordInput.Completed += Pwd_Entered;
        passwordInput.Show();
    }

    void Pwd_Entered(object sender, PopUpEventArgs<string, PopUpResult> e)
    {
        //You should ony get here when the input is not null.
        MessageBox.Show(e.Result);
    }

Xaml to trigger the password prompt

 <Grid VerticalAlignment="Top" x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
  <Button Content="ShowPasswordPrompt" Tap="PasswordPrompt"></Button>
</Grid>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top