小编Wal*_* IV的帖子

通过布尔值设置LinearLayout背景颜色

我正在尝试使用MvxValueConverter根据布尔值设置LinearLayout的背景颜色.转换器看起来像这样:

public class BackgroundColorValueConverter : MvxValueConverter<bool, MvxColor>
{
    private static readonly MvxColor TrueBGColor = new MvxColor(0xDB, 0xFF, 0xCE);
    private static readonly MvxColor FalseBGColor = new MvxColor(0xD6, 0xF6, 0xFF);

    protected override MvxColor Convert(bool value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return value ? TrueBGColor : FalseBGColor;
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的AXML布局中,我有以下代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    local:MvxBind="BackgroundColor MyBooleanValue, Converter=BackgroundColor">
  <TextView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:gravity="center"
      android:textSize="18dp"
      local:MvxBind="Text MyText" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Failed to create target binding for binding BackgroundColor for MyBooleanValue …
Run Code Online (Sandbox Code Playgroud)

android converter mvvmcross xamarin

8
推荐指数
1
解决办法
1733
查看次数

标签 统计

android ×1

converter ×1

mvvmcross ×1

xamarin ×1