MvvmCross:iOS设备上的绑定警告

时间:2015-02-07 20:41:50

标签: ios binding xamarin mvvmcross

我已经创建了像Stuart在本帖子中所说的绑定:MvvmCross - How to bind UIView.Layer.AnyProperty (Xamarin.iOS) to a property on a viewmodel?

这适用于模拟器,但不适用于iOS设备。我已经添加了LinkerPleaseInclude.cs,但这没有改变任何内容。

绑定到BorderWidth工作正常,绑定到BorderColor会显示警告。

LinkerPleaseInclude.cs:

public class LinkerPleaseInclude
{
    public void Include(UIButton uiButton)
    {
        uiButton.TouchUpInside += (s, e) =>
                                  uiButton.SetTitle(uiButton.Title(UIControlState.Normal), UIControlState.Normal);
    }

    public void Include(UIBarButtonItem barButton)
    {
        barButton.Clicked += (s, e) =>
                             barButton.Title = barButton.Title + "";
    }

    public void Include(UITextField textField)
    {
        textField.Text = textField.Text + "";
        textField.EditingChanged += (sender, args) => { textField.Text = ""; };
    }

    public void Include(UITextView textView)
    {
        textView.Text = textView.Text + "";
        textView.Changed += (sender, args) => { textView.Text = ""; };
    }

    public void Include(UILabel label)
    {
        label.Text = label.Text + "";
    }

    public void Include(UIImageView imageView)
    {
        imageView.Image = new UIImage();
    }

    public void Include(UIDatePicker date)
    {
        date.Date = date.Date.AddSeconds(1);
        date.ValueChanged += (sender, args) => { date.Date = DateTime.MaxValue.ToNSDate(); };
    }

    public void Include(UISlider slider)
    {
        slider.Value = slider.Value + 1;
        slider.ValueChanged += (sender, args) => { slider.Value = 1; };
    }

    public void Include(UISwitch sw)
    {
        sw.On = !sw.On;
        sw.ValueChanged += (sender, args) => { sw.On = false; };
    }

    public void Include(INotifyCollectionChanged changed)
    {
        changed.CollectionChanged += (s,e) => { var test = string.Format("{0}{1}{2}{3}{4}", e.Action,e.NewItems, e.NewStartingIndex, e.OldItems, e.OldStartingIndex); } ;
    }
}

我的绑定代码:

bindingSet.Bind(this.MyUITextField.Layer)
              .For(x => x.BorderColor)
              .To(x => x.MyViewModelProperty.IsValid)
              .WithConversion("ValidationStyleBorderColor");
bindingSet.Bind(this.MyUITextField.Layer)
              .For(x => x.BorderWidth)
              .To(x => x.MyViewModelProperty.IsValid)
              .WithConversion("ValidationStyleBorderWidth");
bindingSet.Apply();

我的转换器:

public class ValidationStyleBorderColorValueConverter : MvxValueConverter<bool, CGColor>
{
    protected override CGColor Convert(bool value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return value == true ? Themes.Default.HighlightColor.CGColor : Themes.Default.ErrorColor.CGColor;
    }
}

警告:MvxBind:警告:22,91无法为MyViewModelProperty.IsValid绑定BorderColor创建目标绑定

我做错了什么?

1 个答案:

答案 0 :(得分:1)

正如斯图尔特所说,包括LinkerPleaseInclude中的Border属性已经成功了。