gpt4 book ai didi

c# - MvvmCross-MvxBind :Warning Failed to create target binding for binding Hello for -empty-

转载 作者:太空宇宙 更新时间:2023-11-03 10:30:59 27 4
gpt4 key购买 nike

我刚刚开始我的第一个 Xamarin 应用程序,并且已经设置了与新解决方案的默认配置非常相似的东西,更改非常少。

应用程序可以正常编译并部署到虚拟设备。

MvxBindingAttributes.xml

<?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

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

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

HomeView.cs

[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

<?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 文本按预期显示,但在输出窗口中我看到此错误:

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-

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

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-

我似乎找不到比去年更新的关于这个问题的任何信息。

为什么它报告绑定(bind)失败但仍按预期绑定(bind)?另外,为什么警告编号 (8.57/9.69) 会更改但错误消息相同?

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

最佳答案

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

HomeView.axml

<TextView
...
local:MvxBind="Hello" />

应该是:

<TextView
...
local:MvxBind="Text Hello" />

Text 类型丢失。

关于c# - MvvmCross-MvxBind :Warning Failed to create target binding for binding Hello for -empty-,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30216024/

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