首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MvvmCross -MvxBind:警告未能为绑定Hello空创建目标绑定

MvvmCross -MvxBind:警告未能为绑定Hello空创建目标绑定
EN

Stack Overflow用户
提问于 2015-05-13 13:17:25
回答 2查看 1.3K关注 0票数 1

我刚刚开始我的第一个Xamarin应用程序,并且已经设置了基本的东西,就像一个新解决方案的默认配置一样,所做的更改非常小。

应用程序编译得很好,并且也部署到虚拟设备上。

MvxBindingAttributes.xml

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<resources>
  <declare-styleable name="MvxBinding">
    <attr name="MvxBind" format="string"/>
    <attr name="MvxLang" format="string"/>
  </declare-styleable>
  <declare-styleable name="MvxControl">
    <attr name="MvxTemplate" format="string"/>
  </declare-styleable>
  <declare-styleable name="MvxListView">
    <attr name="MvxItemTemplate" format="string"/>
    <attr name="MvxDropDownItemTemplate" format="string"/>
  </declare-styleable>
  <item type="id" name="MvxBindingTagUnique"/>
  <declare-styleable name="MvxImageView">
    <attr name="MvxSource" format="string"/>
  </declare-styleable>
</resources>

HomeViewModel.cs

代码语言:javascript
复制
public class HomeViewModel : MvxViewModel
{
    /// <summary>
    /// The _hello.
    /// </summary>
    private string _hello = "Hello MvvmCross";

    /// <summary>
    /// Gets or sets the hello.
    /// </summary>
    public string Hello
    {
        get
        {
            return _hello;
        }

        set
        {
            _hello = value;
            RaisePropertyChanged(() => Hello);
        }
    }
}

App.cs

代码语言:javascript
复制
public class App : Cirrious.MvvmCross.ViewModels.MvxApplication
{
    /// <summary>
    /// The initialize.
    /// </summary>
    public override void Initialize()
    {
        CreatableTypes().EndingWith("Service").AsInterfaces().RegisterAsLazySingleton();
        RegisterAppStart<HomeViewModel>();
    }
}

HomeView.cs

代码语言:javascript
复制
[Activity(Label = "View for HomeViewModel")]
public class HomeView : MvxActivity
{
    /// <summary> The on create. </summary>
    /// <param name="bundle"> The bundle. </param>
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        SetContentView(Resource.Layout.HomeView);
    }
}

HomeView.axml

代码语言:javascript
复制
<?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:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="40dp"
        local:MvxBind="Text Hello" />
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="40dp"
        local:MvxBind="Hello" />
</LinearLayout>

当我在设备上运行此操作时,Hello MvvmCross文本将按预期显示,但在输出窗口中,我会看到以下错误:

代码语言:javascript
复制
MvxBind:Warning:  8.57 Failed to create target binding for binding Hello for -empty-
[0:] MvxBind:Warning:  8.57 Failed to create target binding for binding Hello for -empty-
05-13 12:56:37.654 I/mono-stdout(  683): MvxBind:Warning:  8.57 Failed to create target binding for binding Hello for -empty-

如果我关闭虚拟设备上的应用程序,然后再次启动它,就会得到:

代码语言:javascript
复制
MvxBind:Warning: 97.69 Failed to create target binding for binding Hello for -empty-
[0:] MvxBind:Warning: 97.69 Failed to create target binding for binding Hello for -empty-
05-13 12:58:06.802 I/mono-stdout(  683): MvxBind:Warning: 97.69 Failed to create target binding for binding Hello for -empty-

我似乎找不到比去年更近期的关于这个问题的任何东西。

为什么它报告绑定失败而又像预期的那样绑定呢?此外,为什么警告号(8.57 / 9.69)会更改,但具有相同的错误信息?

我还在解决方案中包含了默认的LinkerPleaseInclude.cs文件,所以我现在对此感到有点困惑。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-05-14 12:49:26

原来我的一个绑定声明是不正确的:

HomeView.axml

代码语言:javascript
复制
<TextView
    ...
    local:MvxBind="Hello" />

应:

代码语言:javascript
复制
<TextView
    ...
    local:MvxBind="Text Hello" />

Text型缺失。

票数 2
EN

Stack Overflow用户

发布于 2015-05-13 13:45:51

您需要将视图模型设置为在活动中使用。

将这一行:public class HomeView : MvxActivity更改为:public class HomeView : MvxActivity<HomeViewModel>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30216024

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档