gpt4 book ai didi

android - MvvmCross Android BackgroundColor 未绑定(bind)到 ViewModel

转载 作者:太空狗 更新时间:2023-10-29 16:39:36 24 4
gpt4 key购买 nike

我很难获得一个基本的 MvvmCross Android 示例,其中 RelativeLayout 的 BackgroundColor 绑定(bind)到 ViewModel。

应用程序运行,出现一些文本,我希望我的背景变成黄色。但是,背景颜色保持不变。

我在我的 Core 和 Droid 项目以及 MvvmCross - Color 插件中都包含了 Hot Tuna 入门包。我的 Droid 项目自动获得了 ColorPluginBootstrap.cs

布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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 NativeColor(BackgroundColor)">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="20sp"
android:gravity="center"
android:text="Text to make sure the layout inflates" />
</RelativeLayout>

View 模型

public class ViewModel : MvxViewModel
{
RGBAColorConverter _rgbaConverter;
public ViewModel()
{
var color = "#ffedff00";
_rgbaConverter = new RGBAColorConverter();
BackgroundColor = _rgbaConverter.Convert(color);
}

private MvxColor _backgroundColor;
public MvxColor BackgroundColor
{
get { return _backgroundColor; }
set
{
_backgroundColor = value;
RaisePropertyChanged(() => BackgroundColor);
}
}
}

绑定(bind)有效 - 我尝试制作其他字符串形式的 ViewModel 属性来执行简单的文本绑定(bind)。所有这一切似乎都很好。

我在 BackgroundColor ViewModel 属性的 getter 上放置了调试断点,我可以按预期看到 MvxColor。

我的颜色绑定(bind)方案缺少什么?

  • 我没有在 Setup.cs 中做任何额外的事情
  • 我没有在我的 Droid 项目中创建任何其他连接类
  • 我还没有创建任何特定于 Android 的颜色转换器实现

最佳答案

我刚刚编写了一个测试应用程序,它似乎对我有用 - 使用 3.0.14 nuget 二进制文件。

此外,ValueConverters 测试应用程序似乎工作正常 - https://github.com/MvvmCross/MvvmCross-Tutorials/tree/master/ValueConversion

看着你的样本,我唯一能想到的是,也许你只是在测试透明颜色(RGBA #ffedff00 的 Alpha=0)

如果不是,您能否发布更多内容 - 也许是某处的完整样本?

关于android - MvvmCross Android BackgroundColor 未绑定(bind)到 ViewModel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20169906/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com