对我来说 UIButton 绑定到 TitleLabel 不起作用。我想出了自定义绑定,它工作得很好而且很灵活:
应用绑定:
set.Bind(FinishedButton).For(UIButtonTextBinding.Property).To(v => v.FinishActionText);
绑定代码:
public class UIButtonTextBinding : MvxTargetBinding
{
public const string Property = "ButtonText";
protected UIButton View
{
get { return Target as UIButton; }
}
public UIButtonTextBinding(UIButton target)
: base(target)
{
}
public override void SetValue(object value)
{
var view = View;
if (view == null)
return;
var stringValue = value as string;
view.SetTitle(stringValue, UIControlState.Normal);
}
public override Type TargetType
{
get { return typeof(string); }
}
public override MvxBindingMode DefaultMode
{
get { return MvxBindingMode.OneWay; }
}
}