2016-04-27 60 views
0

我試圖綁定在Android的MapView中點擊標記時點擊Apprear的信息內容窗口。在Android上使用ViewModel與MvvmCross綁定Android.Views.View

我創建了一個自定義管理器類,它接收ItemSource和MapView(ObservableCollection),並在集合更改時在地圖上添加標記。

現在我想由GetInfoContents(Marker marker)

目前,我不得不檢索填充字段如下手動生成InfoContent窗口綁定,但我想田間地頭直接與佈局數據綁定當前視圖模型

public override Android.Views.View GetInfoContents(object item, Marker marker) 
     { 
      var vm = item as DetailCalloutViewModel; 
      if (vm != null) { 
       var view = _layoutInflater.Inflate(Resource.Layout.view_store_marker_info_window, null); 
       var address = view.FindViewById<TextView>(Resource.Id.address); 
       var description = view.FindViewById<TextView>(Resource.Id.description); 
       var badge = view.FindViewById<TextView>(Resource.Id.badge); 

       address.Text = vm.Address; 
       description.Text = vm.Location.Description; 
       badge.Text = vm.BadgeNumber; 
       return view; 
      } 

      return null; 
     } 

回答

0

Mabye你應該嘗試從BindingInflate的BindingContext:

var view = this.BindingInflate(Resource.Layout.SomeLayout, null); 

更新:對於您的問題,我不確定這是不是太hacky,但您可以在您的MainActivity中使用Mvx.RegisterSingleton(BindingContext);,然後通過var bindingContext = Mvx.Resolve<IMvxBindingContext>();解決此問題。


另一種方法:你可以訂閱你vm.PropertyChanged事件和處理自己的變化 - 實際編寫自己的BindingContext。

+0

我有一個管理器,可以將可觀察集合中的標記綁定到不同的類中。該類的簽名是'public public class BaseMapViewDataBindingSource:Java.Lang.Object,IOnMapReadyCallback,GoogleMap.IInfoWindowAdapter '和this。 BindingInflate從那裏不可用 – wishmaster

+0

好吧,我看到了問題。我更新了一些,但不是很高興。沒有BindingContext,你不能使用MvvmCross Binding。 – Matt

相關問題