0
votes

I am trying to bind ULabel to a Command in a core but can't figure out why it is not working for me. I read that UILabel is bindable to a default Text property so I have the following simple tester to demonstrate:

in Touch code I have the following ViewDidLoad:

        var tipLabel = new UILabel(new RectangleF(10, 20, 300, 40));
        Add(tipLabel);

        var loginBtn = new UIButton(UIButtonType.RoundedRect) { Frame = new RectangleF(10, 100, 100, 40) };
        loginBtn.SetTitle("Set Text", UIControlState.Normal);

        var tap = new UITapGestureRecognizer(() =>
        {
            tipLabel.Text = DateTime.Now.ToShortTimeString();
        });
        loginBtn.AddGestureRecognizer(tap);
        Add(loginBtn);


        var set = this.CreateBindingSet<FirstView, FirstViewModel>();
        set.Bind(tipLabel).For(p=>p.Text).To(vm=>vm.TestCommand);
        set.Apply();

and in a core:

     private MvxCommand _testCommand;

    public ICommand TestCommand
    {
        get { return this._testCommand ?? (this._testCommand = new MvxCommand(this.Test)); }
    }


    public void Test()
    {
    }

what am I missing?

Thank you Mark

1
Command should be used for actions like Click and etc. Why you binding text field to Command? You should bind it to string property - xakpc

1 Answers

0
votes

You are effectively binding the Text property to a command. This won't work. I would use a UIButton and adjust its properties so it looks like a label then bind to its click event to change the button label.