如何在 xamarin.forms 中验证 Button clicked 事件和 Textchanged 事件上的 Entry 控件?

How to validate Entry control on Button clicked Event and Textchanged event in xamarin.forms?

如何在 xamarin.forms 中验证 Entry 控件?

我想在 xamarin.forms 本机应用程序中验证按钮单击事件上的 Entry 控件。

我已经尝试使用 xamarin.forms 行为

如何使用其他方法进行验证?

我想对文本更改事件的每个条目控件进行验证。

想在进入控制结束后显示验证是这样的....

RegisterButton.Clicked += (sender, e) => {

  if (Validate()) {
    // complete Registration process
  }

};

private bool Validate() {

  // perform test for each field on page
  if (string.IsNullOrEmpty(NameField.Text)) {
    DisplayAlert("Error","Please enter a value for Name", "OK");
    return false;
  }

  // repeat for next field - some fields may have different, 
  // or multiple validations, depending on your business rules

  // if all validations pass, then return true
  return true;
}