【发布时间】:2016-06-09 14:34:13
【问题描述】:
我试图为 MVVMCross 实现 ValueConverter,但显然它没有像我预期的那样工作。所以目前我刚刚得到另一个属性,它为我进行转换(MvxColor 到 TextColor)并将它绑定到我的布局。 但是ofc我宁愿使用值转换器,所以也许你知道我做错了什么:
我当前遇到的绑定错误:
06-09 16:29:29.820 I/MvxBind (16312): 61,64 Problem seen during binding execution for binding TextColor for Changed - problem InvalidCastException: Specified cast is not valid.
06-09 16:29:29.820 I/MvxBind (16312): at MvvmCross.Plugins.Color.Droid.BindingTargets.MvxTextViewTextColorBinding.SetValueImpl (System.Object target, System.Object value) [0x0000a] in <filename unknown>:0
06-09 16:29:29.820 I/MvxBind (16312): at MvvmCross.Binding.Bindings.Target.MvxConvertingTargetBinding.SetValue (System.Object value) [0x00088] in <filename unknown>:0
06-09 16:29:29.820 I/MvxBind (16312): at MvvmCross.Binding.Bindings.MvxFullBinding.UpdateTargetFromSource (System.Object value) [0x00024] in <filename unknown>:0
MvxBind:Error: 61,64 Problem seen during binding execution for binding TextColor for Changed - problem InvalidCastException: Specified cast is not valid.
06-09 16:29:29.820 I/mono-stdout(16312): MvxBind:Error: 61,64 Problem seen during binding execution for binding TextColor for Changed - problem InvalidCastException: Specified cast is not valid.
06-09 16:29:29.820 I/mono-stdout(16312): at MvvmCross.Plugins.Color.Droid.BindingTargets.MvxTextViewTextColorBinding.SetValueImpl (System.Object target, System.Object value) [0x0000a] in <filename unknown>:0
at MvvmCross.Plugins.Color.Droid.BindingTargets.MvxTextViewTextColorBinding.SetValueImpl (System.Object target, System.Object value) [0x0000a] in <filename unknown>:0
at MvvmCross.Binding.Bindings.Target.MvxConvertingTargetBinding.SetValue (System.Object value) [0x00088] in <filename unknown>:0
06-09 16:29:29.830 I/mono-stdout(16312): at MvvmCross.Binding.Bindings.Target.MvxConvertingTargetBinding.SetValue (System.Object value) [0x00088] in <filename unknown>:0
at MvvmCross.Binding.Bindings.MvxFullBinding.UpdateTargetFromSource (System.Object value) [0x00024] in <filename unknown>:0
06-09 16:29:29.830 I/mono-stdout(16312): at MvvmCross.Binding.Bindings.MvxFullBinding.UpdateTargetFromSource (System.Object value) [0x00024] in <filename unknown>:0
[0:] MvxBind:Error: 61,64 Problem seen during binding execution for binding TextColor for Changed - problem InvalidCastException: Specified cast is not valid.
at MvvmCross.Plugins.Color.Droid.BindingTargets.MvxTextViewTextColorBinding.SetValueImpl (System.Object target, System.Object value) [0x0000a] in <filename unknown>:0
at MvvmCross.Binding.Bindings.Target.MvxConvertingTargetBinding.SetValue (System.Object value) [0x00088] in <filename unknown>:0
at MvvmCross.Binding.Bindings.MvxFullBinding.UpdateTargetFromSource (System.Object value) [0x00024] in <filename unknown>:0
我的布局片段:
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true"
android:inputType="numberDecimal|numberSigned"
android:textColor="@color/schaefflerlightgreen"
local:MvxBind="TextColor Changed,Converter=MvxBoolToColorValueConverter" />
我试过的两个转换器类:
public class MvxBoolToMvxColorValueConverter: MvxColorValueConverter<bool>
{
protected override MvxColor Convert(bool value, object parameter, CultureInfo culture)
{
if (value)
{
// FF0000
return new MvxColor(255, 0, 0);
}
//227D41
return new MvxColor(34, 125, 65);
}
}
public class MvxBoolToColorValueConverter : MvxValueConverter<bool, Color>
{
protected override Color Convert(bool value, Type targetType, object parameter, CultureInfo culture)
{
if (value)
{
// FF0000
return new Color(255, 0, 0);
}
//227D41
return new Color(34, 125, 65);
}
}
问题是绑定通常使用 MvxColor-Property,只是转换似乎是一个问题。所以可能我只是错过了一些东西。
非常感谢您的帮助。
伊迪丝:还有财产……
public bool Changed { get { return m_sValue != m_sSyncValue; } }
【问题讨论】:
标签: c# xamarin xamarin.android converter mvvmcross