Reputation: 384
I´ve created my bindings like Stuart told in this Post: MvvmCross - How to bind UIView.Layer.AnyProperty (Xamarin.iOS) to a property on a viewmodel?
This works well on simulator, but not on a iOS device. I already added LinkerPleaseInclude.cs but this changed nothing.
Binding to BorderWidth works perfectly, binding to BorderColor shows a warning.
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); } ;
}
}
My code for binding:
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();
My converter:
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;
}
}
And the warning: MvxBind: Warning: 22,91 Failed to create target binding for binding BorderColor for MyViewModelProperty.IsValid
What am I doing wrong?
Upvotes: 0
Views: 665
Reputation: 384
As Stuart told, including the Border properties in LinkerPleaseInclude made it.
Upvotes: 1