2015-02-07 87 views
0

从来就创建了绑定,像斯图尔特告诉记者,在这个帖子:MvvmCross - How to bind UIView.Layer.AnyProperty (Xamarin.iOS) to a property on a viewmodel?MvvmCross:iOS设备上绑定警告

这行之有效的模拟器,而不是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无法创建绑定BorderColor for MyViewModelProperty.IsValid的目标绑定

我在做什么错?

+0

是否还有其他跟踪文本?例如在发布警告之前? – Stuart 2015-02-08 09:29:29

+0

不,只是。 mvx:诊断:23,55显示视图模型MyViewModel TouchNavigation:诊断:23,55请求导航 MvxBind:警告:24,20无法创建目标绑定以绑定BorderColor for MyViewModel.IsValid – 2015-02-09 09:00:37

+0

没有创意?仍然有这个警告.. – 2015-02-22 20:22:25

回答

1

正如斯图尔特告诉的,包括LinkerPleaseInclude中的Border属性所做的。