This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MvxTextViewTextColorBinding | |
: MvxBaseAndroidTargetBinding | |
{ | |
private readonly TextView _textView; | |
public MvxTextViewTextColorBinding(TextView textView) | |
{ | |
_textView = textView; | |
} | |
public override void SetValue(object value) | |
{ | |
_textView.SetTextColor((Color)value); | |
} | |
public override MvxBindingMode DefaultMode | |
{ | |
get { return MvxBindingMode.OneWay; } | |
} | |
public override Type TargetType | |
{ | |
get { return typeof(Color); } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MvxViewBackgroundColorBinding | |
: MvxBaseAndroidTargetBinding | |
{ | |
private readonly View _view; | |
public MvxViewBackgroundColorBinding(View view) | |
{ | |
_view = view; | |
} | |
public override void SetValue(object value) | |
{ | |
_view.SetBackgroundColor((Color)value); | |
} | |
public override MvxBindingMode DefaultMode | |
{ | |
get { return MvxBindingMode.OneWay; } | |
} | |
public override Type TargetType | |
{ | |
get { return typeof(Color); } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected override void FillTargetFactories(Cirrious.MvvmCross.Binding.Interfaces.Bindings.Target.Construction.IMvxTargetBindingFactoryRegistry registry) | |
{ | |
registry.RegisterFactory(new MvxCustomBindingFactory<View>("BackgroundColor", textView => new MvxViewBackgroundColorBinding(textView))); | |
registry.RegisterFactory(new MvxCustomBindingFactory<TextView>("TextColor", textView => new MvxTextViewTextColorBinding(textView))); | |
} |
Hi Stuart, this looks great! However, I'm struggling to find MvxBaseAndroidTargetBinding - what namespace is this in, and do I need to install a specific nuget package to make use of it? Thanks! David
ReplyDeleteDavid, use MvxAndroidTargetBinding from MvvmCross.Binding.Droid.Target namespace.
DeleteExample of usage
public class MyCustomBinding: MvxAndroidTargetBinding
{
public MyCustomBinding(object target) : base(target)
{
}
public override Type TargetType => typeof(TextView);
protected override void SetValueImpl(object target, object value)
{
if(value!=null)
{
var c = new Color(((MvxColor) value).ARGB);
((TextView)target).SetTextColor(c);
}
}
}