Forum Xamarin.Forms

ViewCell - sub views binding recommendation

DanielLDanielL PLInsider ✭✭✭✭

Giving some sample code:

namespace SomeNamespace.Controls
{
    public class ExampleCell : ViewCell
    {
        Label label;

        public ExampleCell()
        {
            label = new Label() {
                Font = Font.SystemFontOfSize(NamedSize.Medium),
                VerticalOptions = LayoutOptions.CenterAndExpand,
            };

            View = label;
        }


        public static readonly BindableProperty TextProperty = 
            BindableProperty.Create<ExampleCell, string> (p => p.Text, string.Empty);

        public string Text
        {
            get
            {
                return (string)GetValue(TextProperty);
            }
            set
            {
                SetValue(TextProperty, value);
            }
        }
    }
}

What is recommended way for binding "label" TextProperty with "Text " TextProperty? Should I set binding or update label.Text within Text property setter? Or maybe within OnBindingContextChanged method? Please, share your opinions.

Sign In or Register to comment.