Binding problem

KurtMcKenzieKurtMcKenzie USMember
edited December 2016 in Xamarin.Forms

Hi there, I'm trying to use benefits of XAML binding in a custom control. However something is wrong that i can't get values out of my control

XAML:
///

///

public class ValidatedEntry : Entry
{
public bool HasValidInputValid { get; set; }
}
public class FormEntry2 : StackLayout
{
public ValidatedEntry TextEntry { get; set; }
Image _img_validationStatus;
public FormEntry2() : base()
{
TextEntry = new ValidatedEntry();

        Orientation = StackOrientation.Horizontal;


        _img_validationStatus = new Image() { Source = "valid.png" };

        _img_validationStatus.IsVisible = false;
        this.Children.Add(TextEntry);
        this.Children.Add(_img_validationStatus);


        HorizontalOptions = LayoutOptions.FillAndExpand;
        TextEntry.HorizontalOptions = LayoutOptions.FillAndExpand;

    }

    private void _entry_TextChanged(object sender, TextChangedEventArgs e)
    {
        if (_InputType != EntryInputType.NotSpecified)
        {
            if (string.IsNullOrEmpty(TextEntry.Text))
            {
                _img_validationStatus.IsVisible = false;
            }
            else if (TextEntry.HasValidInputValid)
            {
                _img_validationStatus.IsVisible = true;
                _img_validationStatus.Source = "valid.png";
            }
            else
            {
                _img_validationStatus.IsVisible = true;
                _img_validationStatus.Source = "invalid.png";
            }
        }
    }

public static readonly BindableProperty TextProperty = BindableProperty.Create("Text", typeof(string), typeof(Entry), null);
public string Text
{
get
{
return (string)GetValue(TextProperty);
}
set
{
TextEntry.Text = value;
SetValue(TextProperty, value);

        }


    }

}

In viewModel i have :

//
public UserModel User { get; set; } //Has Email Property
///

My problem is when i'm reading User.Email its always null

Any help would be great.

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Two things
    1) How to mark up code here:
    image

    2) Your issue as stated is about the email property on the UserModel class. But you haven't provided that class or anyplace you're setting the .Email property. So I don't see how anyone here could help.

    I can point out that your User property doesn't honor INotifyPropertyChanged or raise a notice when it is set... So no binding would be aware of when a new user is assigned. Maybe the issue is that you're just looking at the wrong user.

Sign In or Register to comment.