0
votes

When we bind an object we do it like this:

label.setBinding(Label.TextProperty, "task");

The thing is that I have a variable which it gets a value named "task", based on the value it gets ("yes" or "not") I will disable a view from my viewcell, but I cant get the value of the label im binding to make the comparisons, so is it posible to bind a variable of string type?

2

2 Answers

0
votes

Here is the code to Bind string with the label and show or hide the view based on the value of task,

    public SamplePage()
    {
        BindingContext = this;
        InitializeComponent();
        label.SetBinding(Label.TextProperty, "Task");
        view.SetBinding(View.IsVisibleProperty, "Visibility");
    }

    string task ="Yes";
    public string Task
    {
        get { return task; }
        set {
          task = value;
            Visibility = task == "Yes" ? true : false;
        }
    }

    public bool Visibility { get; set; }
0
votes

Sure you can bind string value to Label.TextProperty. I would recommend to bind it this way, in my opinion it's more clear way.

label.SetBinding<YourBindingContextTypeName>(Label.TextProperty, vm => vm.Task);

P.S.

Remember to notify the view about view model property changes, it can be done in several ways. Read this for more info.