我刚刚开始我的第一个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-我似乎找不到比去年更近期的关于这个问题的任何东西。
为什么它报告绑定失败而又像预期的那样绑定呢?此外,为什么警告号(8.57 / 9.69)会更改,但具有相同的错误信息?
我还在解决方案中包含了默认的LinkerPleaseInclude.cs文件,所以我现在对此感到有点困惑。
发布于 2015-05-14 12:49:26
原来我的一个绑定声明是不正确的:
HomeView.axml
<TextView
...
local:MvxBind="Hello" />应:
<TextView
...
local:MvxBind="Text Hello" />Text型缺失。
发布于 2015-05-13 13:45:51
您需要将视图模型设置为在活动中使用。
将这一行:public class HomeView : MvxActivity更改为:public class HomeView : MvxActivity<HomeViewModel>
https://stackoverflow.com/questions/30216024
复制相似问题