Search code examples
c#bindingxamarin.iosxamarinmvvmcross

MvvmCross Bind to UIButton.TitleLabel.Text


I am attempting to bind to the text property of TitleLabel on a UIButton using MvvmCross for Xamarin.iOS. Here's what I have so far...

set.Bind(btnFoo).For(btn => btn.TitleLabel.Text).To(vm => vm.BtnFooText);

I've also tried...

set.Bind(btnFoo.TitleLabel).For(lbl => lbl.Text).To(vm => vm.BtnFooText);

Neither of which seem to work. I appreciate the help!


Solution

  • For debugging issues, enabling trace may help - see MvvmCross Mvx.Trace usage

    For binding a property on a fixed pre-existing subcontrol of a subcontrol then this approach should work:

    set.Bind(sub.subSub).For(c => c.PropertyName).To(vm => vm.Foo);
    

    However, that won't continue to work if the sub control then changes its sub control at any point. For those cases, look at custom bindings - eg see http://slodge.blogspot.co.uk/2013/06/n28-custom-bindings-n1-days-of-mvvmcross.html

    For the specific case of a uibutton, you can just bind its "Title" - see Fluent Bindings and UIButton titles