Немного поздно, но у меня было такое же требование, и я просто сделал это сейчас.
Добавьте в ваш файл настройки (у меня есть два пользовательских свойств связывания, Style и Резюме):
protected override void FillTargetFactories(IMvxTargetBindingFactoryRegistry registry)
{
base.FillTargetFactories(registry);
registry.RegisterFactory(new MvxCustomBindingFactory<TextView>("Style", textView => new StyleTextViewBinding(textView)));
registry.RegisterFactory(new MvxCustomBindingFactory<TextView>("Summary", textView => new SummaryTextViewBinding(textView)));
}
В моей TextView (мой пользовательский связывание Стиль очевидно, Текст и TextColor конверторы):
<TextView
style="@style/TeamDifficulty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/dummy_title"
local:MvxBind="Text TeamDifficultyText(RowItem.DifficultyEnumCaptain1Int); TextColor TeamDifficultyTextColor(RowItem.DifficultyEnumCaptain1); Style RowItem.DifficultyEnumCaptain1;" />
И фактический код (в основном он проверяет, если мой текст пуст или нет, если да, то это будет смелым это так мой конвертер добавит значение к нему после):
public class StyleTextViewBinding : MvxAndroidTargetBinding
{
readonly TextView _textView;
public StyleTextViewBinding(TextView textView) : base(textView)
{
_textView = textView;
}
#region implemented abstract members of MvxConvertingTargetBinding
protected override void SetValueImpl(object target, object value)
{
_textView.SetTypeface(_textView.Typeface, Android.Graphics.TypefaceStyle.Bold);
if (value != null && Convert.ToBoolean(value))
_textView.SetTypeface(_textView.Typeface, Android.Graphics.TypefaceStyle.Normal);
}
#endregion
public override Type TargetType
{
get { return typeof(bool); }
}
public override MvxBindingMode DefaultMode
{
get { return MvxBindingMode.OneWay; }
}
}
Надеется, что это помогает!
Вам, скорее всего, придется использовать ValueConverter, так как вы не можете передавать типы Android через строки в привязках. – Cheesebaron
Вы когда-нибудь находили способ сделать это? –
@AaronBratcher Я просто сделал это, проверьте ниже. – PmanAce