changement de candidat à l'investissement

This commit is contained in:
Paul Schneider 2017-01-26 11:04:03 +01:00
commit be3087fff6
351 changed files with 359 additions and 497 deletions

View file

@ -0,0 +1,53 @@
using System;
using System.Text.RegularExpressions;
using Xamarin.Forms;
namespace BookAStar.Behaviors
{
public class RegexValidatorBehavior : Behavior<Entry>
{
private string regexp = @"^([\d\w]+)$";
// Creating BindableProperties with Limited write access: http://iosapi.xamarin.com/index.aspx?link=M%3AXamarin.Forms.BindableObject.SetValue(Xamarin.Forms.BindablePropertyKey%2CSystem.Object)
static readonly BindablePropertyKey IsValidPropertyKey = BindableProperty.CreateReadOnly("IsValid", typeof(bool), typeof(RegexValidatorBehavior), false);
public static readonly BindableProperty IsValidProperty = IsValidPropertyKey.BindableProperty;
public bool IsValid
{
get { return (bool)base.GetValue(IsValidProperty); }
private set { base.SetValue(IsValidPropertyKey, value); }
}
protected string Regexp
{
get
{
return regexp;
}
set
{
regexp = value;
}
}
protected override void OnAttachedTo(Entry bindable)
{
bindable.TextChanged += HandleTextChanged;
}
void HandleTextChanged(object sender, TextChangedEventArgs e)
{
IsValid = (Regex.IsMatch(e.NewTextValue, regexp, RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250)));
((Entry)sender).TextColor = IsValid ? Color.Default : Color.Red;
}
protected override void OnDetachingFrom(Entry bindable)
{
bindable.TextChanged -= HandleTextChanged;
}
}
}