2013-07-18 46 views

回答

9

好吧,經過很多的鬥爭,我終於得到了答案。我不得不做下列事情。

1)增加了一個import語句:

using Cirrious.MvvmCross.Binding.BindingContext; 

2)的添加以下代碼:

protected override void OnCreate(Bundle bundle) 
{ 
    base.OnCreate(bundle); 
    SetContentView(Resource.Layout.Hello); 

    TableLayout containerLayout = this.FindViewById<TableLayout>(Resource.Id.containerLayout); 
    if (containerLayout != null) 
    {       
     TableRow newRow = new TableRow(base.ApplicationContext); 
     newRow.SetMinimumHeight(50); 

     var txtRace = new EditText(ApplicationContext); 
     txtRace.Hint = "Race"; 

     var bindingSet = this.CreateBindingSet<HelloView, HelloViewModel>(); 
     bindingSet.Bind(txtRace).To(vm => vm.Race); 
     bindingSet.Apply(); 

     newRow.AddView(txtRace); 
     containerLayout.AddView(newRow); 
    } 
} 

我已經有一個 「TableLayout」 在我HelloView.axml文件和所有我這樣做是創建一個新的EditText框控件(txtRace)並將其添加到視圖中,同時將其綁定到HelloViewModel對象的「Race」屬性。

我花了很多時間試圖找出CreateBindingSet()方法存在的命名空間,因爲VS2012沒有給我任何智力。

希望這可以幫助有人面臨類似的問題。

+0

很高興知道你排序。祝你好運! –

2

是MvvmCross支持在運行時創建的控件的綁定屬性。您可以通過他的N + 1系列中令人敬畏的斯圖亞特先生觀看本教程。 http://www.youtube.com/watch?feature=player_embedded&v=cYu_9rcAJU4

注意:他已經在這個系列中展示過很多次了,但我現在還記得這個在我頭上。

+0

感謝Mohib的迴應。 – Amit

+0

我仍然在這個問題上。我在看這篇文章:http://stackoverflow.com/questions/16724278/mvvmcross-for-android-how-to-do-binding-in-code。我面臨的問題是我無法獲得CreateBindingSet()方法。目前我的活動繼承自MvxActivity。我是否缺少一些程序集引用或名稱空間? – Amit

+0

感謝您的視頻鏈接。斯圖爾特先生提到你的部分可以有多個視圖模型是有幫助的。 –

相關問題