Binding a bool in a ViewCell

RVxRVx USMember ✭✭
edited May 2017 in Xamarin.Forms

Hi
This might be a very stupid question but i have read all i can find on this and i still cant get it to work.

In a Custom ViewCell i have a image.
this image need to change (red cross/green check-mark)
based on a bool property that is in the object the cell is displaying.

I am sure its just me that don't understand the hole DataBinding properly, but i hope someone can push me in the right direction

i have no problems binding to the string and int property's to labels in the Cell.

I have tried:
a horrible hack, where i bind the IsToggled from a Switch and then in "OnAppering" use "if(_Switch.IsToggled)" - didn't work.
to implement the property in a BindableObjectobject, but then i am stranded in how to bind the bool in the ViewCell class :

public class ActivityDto : BindableObject
{
   ...
        public static readonly BindableProperty ReadyProperty = BindableProperty.Create("Ready", typeof(bool), typeof(ActivityDto), false);

        public bool Ready
        {
            get { return (bool)GetValue(ReadyProperty); }
            set { SetValue(ReadyProperty, value); }
        }
}


    public class ActivityCell : ViewCell
    {
        public Image readyImg;

        public ActivityCell()
        {
            readyImg = new Image();
                        if (???)
            {
                //set source
            }
            else
            {
                //set source
            }

Best Answer

Answers

  • RVxRVx USMember ✭✭

    AH! @AlessandroCaliaro thank you so much!
    Works like a charm.

Sign In or Register to comment.