密码输入提示编码4fun-如果输入错误的密码,请继续显示



我正在开发Windows Phone 7.1应用程序,并在Coding4fun库中使用PasswordInputPrompt控件。 我初始化控件并为Completed事件添加EventHandler,然后显示控件。

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

Completed事件处理程序中,我检查如果密码为空白,则我想保留提示

    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???
        }
    }

else零件不起作用。即使输入的密码为空白,该提示也关闭。有人可以向我展示正确的方法吗?

我对此进行了一些快速测试,似乎有效。控件的源代码具有

 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();
}

暗示您可以覆盖方法。

因此,创建一个从控制

继承的类
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);
    }
}

在您的代码后面:

 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触发密码提示

 <Grid VerticalAlignment="Top" x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
  <Button Content="ShowPasswordPrompt" Tap="PasswordPrompt"></Button>
</Grid>

最新更新