在会议示例中有一个示例为“ IsFavorite”添加自定义2向绑定-请参见:
- 绑定-https: //github.com/slodge/MvvmCross/blob/master/Sample%20-%20CirriousConference/Cirrious.Conference.UI.Droid/Bindings/FavoritesButtonBinding.cs
- 在绑定设置
FillTargetFactories
在https://github.com/slodge/MvvmCross/blob/master/Sample%20-%20CirriousConference/Cirrious.Conference.UI.Droid/Setup.cs
在以下示例中进一步解释了此示例:Android中的MVVMCross
Bindings
对于单向“源到目标”自定义绑定,该代码应该更简单-您只需要处理
SetValue-,而无需
FirevalueChanged在任何事件处理代码中调用。
对于textColor,我想绑定应该有点像:
public class MyCustomBinding : MvxbaseAndroidTargetBinding{ private readonly TextView _textView; public MyCustomBinding(TextView textView) { _textView = textView; } public override void SetValue(object value) { var colorValue = (Color)value; _textView.SetTextColor(colorValue); } public override Type TargetType { get { return typeof(Color); } } public override MvxBindingMode DefaultMode { get { return MvxBindingMode.OneWay; } }}
并设置为:
protected override void FillTargetFactories(MvvmCross.Binding.Interfaces.Bindings.Target.Construction.IMvxTargetBindingFactoryRegistry registry) { base.FillTargetFactories(registry); registry.RegisterFactory(new MvxCustomBindingFactory<TextView>("TextColor", (textView) => new MyCustomBinding(textView))); }
注意:我尚未编译此示例代码-当您使其正常工作时,请返回并更正此伪代码:)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)