Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Why propertyChanged is not fired when the default value is null?

$
0
0
I have this attached behavior:

public enum TextType { Email, Phone, }
public static class Validator
{
public static readonly BindableProperty TextTypeProperty = BindableProperty.CreateAttached(
"TextType", typeof(TextType), typeof(Validator), null, propertyChanged: ValidateText);

public static TextType GetTextType(BindableObject view)
{
return (TextType)view.GetValue(TextTypeProperty);
}

public static void SetTextType(BindableObject view, TextType textType)
{
view.SetValue(TextTypeProperty, textType);
}
private static void TextTypeChanged(BindableObject bindable, object oldValue, object newValue)
{
var entry = bindable as Entry;
entry.TextChanged += Entry_TextChanged;
}

private static void Entry_TextChanged(object sender, TextChangedEventArgs e)
{
var entry = sender as Entry;
bool isValid = false;
switch (GetTextType(sender as Entry))
{
case TextType.Email:
isValid = e.NewTextValue.Contains("@);
break;
case TextType.Phone:
isValid = Regex.IsMatch(e.NewTextValue, @^\d+$);
break;
default:
break;
}

if (isValid)
entry.TextColor = Color.Default;
else
entry.TextColor = Color.Red;
}
}

in XAML:



when I run the application on this page, the `TextTypeChanged` is not called, unless I change the `defaultValue` to a member of the `TextType` enum.

Viewing all articles
Browse latest Browse all 204402

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>