2015-05-13 47 views
2

我剛剛啓動我的第一個Xamarin應用程序,並且已將事情設置成新的解決方案的默認配置,只做了很少的更改。MvvmCross - MvxBind:警告無法爲綁定創建目標綁定Hello for -empty-

該應用程序編譯良好,並部署到虛擬設備也很好。

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文件,所以我現在有點困惑。

回答

2

原來我約束力的宣言之一是不正確的:

HomeView.axml

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

應該是:

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

類型Text已經丟失。

0

您需要設置viewmodel以在您的活動中使用。

改變這一行: public class HomeView : MvxActivity 到:public class HomeView : MvxActivity<HomeViewModel>

+0

不幸的是我仍然看到相同的錯誤消息。 – Jammer