Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用MVVMCROSS的TextView上的多值转换器_Android_Xamarin_Xamarin.android_Mvvmcross - Fatal编程技术网

Android 使用MVVMCROSS的TextView上的多值转换器

Android 使用MVVMCROSS的TextView上的多值转换器,android,xamarin,xamarin.android,mvvmcross,Android,Xamarin,Xamarin.android,Mvvmcross,我一直在努力在单文本视图上使用双值转换器 <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/myCustomId" android:textColor="@color/gray_color" android:singleLine="true" an

我一直在努力在单文本视图上使用双值转换器

<TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/myCustomId"
        android:textColor="@color/gray_color"
        android:singleLine="true"
        android:textAppearance="?android:attr/textAppearanceSmall"
        local:MvxBind="Text DateValue, Converter=FormatDate; TextColor Flag, Converter=StatusToColor" />
基本上,我想格式化文本,并根据特定值更改文本颜色

下面是我如何努力做到这一点

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/myCustomId"
        android:textColor="@color/gray_color"
        android:singleLine="true"
        android:textAppearance="?android:attr/textAppearanceSmall"
        local:MvxBind="Text DateValue, Converter=FormatDate; TextColor Flag, Converter=StatusToColor" />
两个转换器都被调用,但我在文本视图中没有得到任何值

请任何一个人引导解决这个问题

谢谢 阿曼

============================ 下面是相同的堆栈跟踪

[0:] 
MvxBind:Warning: 17.34 Value '' could not be parsed as a valid string identifier
[0:] MvxBind:Warning: 17.34 Value '' could not be parsed as a valid string identifier
10-09 19:04:08.972 I/mono-stdout(19422): MvxBind:Warning: 17.34 Value '' could not be parsed as a valid string identifier
[0:] 
MvxBind:Warning: 17.36 Value '' could not be parsed as a valid string identifier
[0:] MvxBind:Warning: 17.36 Value '' could not be parsed as a valid string identifier
10-09 19:04:09.002 I/mono-stdout(19422): MvxBind:Warning: 17.36 Value '' could not be parsed as a valid string identifier
[0:] 
MvxBind:Warning: 17.38 Value '' could not be parsed as a valid string identifier
[0:] MvxBind:Warning: 17.38 Value '' could not be parsed as a valid string identifier
10-09 19:04:09.012 I/mono-stdout(19422): MvxBind:Warning: 17.38 Value '' could not be parsed as a valid string identifier
[0:] 
MvxBind:Warning: 17.39 Value '' could not be parsed as a valid string identifier
[0:] MvxBind:Warning: 17.39 Value '' could not be parsed as a valid string identifier
10-09 19:04:09.032 I/mono-stdout(19422): MvxBind:Warning: 17.39 Value '' could not be parsed as a valid string identifier
[0:] 
MvxBind:Warning: 17.40 Value '' could not be parsed as a valid string identifier
[0:] MvxBind:Warning: 17.40 Value '' could not be parsed as a valid string identifier
10-09 19:04:09.042 I/mono-stdout(19422): MvxBind:Warning: 17.40 Value '' could not be parsed as a valid string identifier
[0:] 
MvxBind:Warning: 17.42 Value '' could not be parsed as a valid string identifier
[0:] MvxBind:Warning: 17.42 Value '' could not be parsed as a valid string identifier
10-09 19:04:09.052 I/mono-stdout(19422): MvxBind:Warning: 17.42 Value '' could not be parsed as a valid string identifier
解决了这个问题

我想和大家分享一下我的成就,以防其他人需要

我简单地更改了StatusToColorValueConverter,如下所示,使其工作

public class StatusToColorValueConverter : MvxValueConverter<int,Color>
    {            
        protected override Color Convert(int value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Color TextColor = Color.Gray;
            switch ((int)value)
            {
                case 1:
                    TextColor = Color.Green;//green
                    break;
                case 2:
                    TextColor = Color.Yellow;
                    break;

                case 3:
                    TextColor = Color.Red;
                    break;
                default:
                    TextColor = Color.Gray;
                    break;
            }
            return TextColor;
        }
    }
公共类StatusToColorValueConverter:MvxValueConverter
{            
受保护的覆盖颜色转换(int值、System.Type targetType、对象参数、System.Globalization.CultureInfo区域性)
{
颜色文本颜色=颜色。灰色;
开关((int)值)
{
案例1:
TextColor=Color.Green;//绿色
打破
案例2:
TextColor=Color.Yellow;
打破
案例3:
TextColor=Color.Red;
打破
违约:
TextColor=Color.Gray;
打破
}
返回文本颜色;
}
}
注意:颜色是Android.Graphics.Color类

现在,只需调用TextView

<TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/myCustomId"
        android:textColor="@color/gray_color"
        android:singleLine="true"
        android:textAppearance="?android:attr/textAppearanceSmall"
        local:MvxBind="Text DateValue, Converter=FormatDate; TextColor Flag, Converter=StatusToColor" />


中有一个有效的TextColor示例-也许可以在该项目中尝试您的值转换器,看看它们是否有效?您好,斯图尔特,谢谢您的回复,我已经看到了链接中提到的示例。除文本值为dateformat converter的datetime和statustocolor converter的值为int外,后面的操作相同…两者都将被调用,但没有显示任何值您不显示“格式化日期的代码”。你确定FormattedDate变量是正确的吗?我想给你一个你可以看到有效的示例和一个不起作用的示例,然后看看你是否能发现差异。。。我看不出与这里发布的部分信息有什么不同。还要检查跟踪-它通常列出有用的输出。您好,Stuart,以MvxBind:Warning:110.77的形式获取消息。无法将值“”解析为有效的字符串标识符
<TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/myCustomId"
        android:textColor="@color/gray_color"
        android:singleLine="true"
        android:textAppearance="?android:attr/textAppearanceSmall"
        local:MvxBind="Text DateValue, Converter=FormatDate; TextColor Flag, Converter=StatusToColor" />