【发布时间】:2015-04-07 20:32:30
【问题描述】:
我已经像 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: Warning: 22,91 Failed to create target binding for binding BorderColor for MyViewModelProperty.IsValid
我做错了什么?
【问题讨论】:
-
还有跟踪文本吗?例如在您发布警告之前?
-
不,仅此而已。 mvx:诊断:23,55 显示 ViewModel MyViewModel TouchNavigation:诊断:23,55 导航请求 MvxBind:警告:24,20 无法为 MyViewModel.IsValid 绑定 BorderColor 创建目标绑定
-
没有想法?仍然有这个警告..
-
您的 LinkerPleaseInclude 不包含对 Border 属性的引用 - 也许您应该尝试添加一些内容?
-
警告消失了。谢谢斯图尔特
标签: ios binding xamarin mvvmcross